Click here to Skip to main content
15,886,919 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Treeview Pin
Mark Salsbery25-Mar-09 6:56
Mark Salsbery25-Mar-09 6:56 
QuestionEditing items in a bound ListBox? Pin
David Veeneman24-Mar-09 12:25
David Veeneman24-Mar-09 12:25 
AnswerRe: Editing items in a bound ListBox? Pin
ABitSmart24-Mar-09 19:00
ABitSmart24-Mar-09 19:00 
GeneralRe: Editing items in a bound ListBox? Pin
David Veeneman25-Mar-09 3:04
David Veeneman25-Mar-09 3:04 
GeneralRe: Editing items in a bound ListBox? Pin
ABitSmart25-Mar-09 3:53
ABitSmart25-Mar-09 3:53 
AnswerRe: Editing items in a bound ListBox? [modified] Pin
David Veeneman25-Mar-09 3:50
David Veeneman25-Mar-09 3:50 
GeneralRe: Editing items in a bound ListBox? Pin
ABitSmart25-Mar-09 4:02
ABitSmart25-Mar-09 4:02 
GeneralRe: Editing items in a bound ListBox? Pin
David Veeneman25-Mar-09 5:29
David Veeneman25-Mar-09 5:29 
Brilliant! Works like a champ. Thanks for your help on this. I cleaned up the code just a bit--complete code and XAML is posted below.

XAML:
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <StackPanel>
        <TextBox Text="{Binding ElementName=playlists, Path=SelectedItem.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        <ListBox Name="playlists" ItemsSource="{Binding Path=Files}" SelectionMode="Single">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="Show file list from DC" Click="Button_Click" />
    </StackPanel>
</Window>


Code:
using System.Windows;
using System.Collections.ObjectModel;
using System.Text;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        private PlayList _playlist = new PlayList();
        public Window1()
        {
            InitializeComponent();
            playlists.DataContext = _playlist;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            foreach (MyFile file in _playlist.Files)
            {
                sb.Append(file.Name + " ");
            }
            MessageBox.Show(sb.ToString());
        }
    }

    public class MyFile 
    { 
        public string Name { get; set; } 
    }

    public class PlayList 
    {
        public ObservableCollection<MyFile> Files { get; set; }

        public PlayList() 
        {
            Files = new ObservableCollection<MyFile>();
            Files.Add(new MyFile { Name = "a" });
            Files.Add(new MyFile { Name = "b" });
            Files.Add(new MyFile { Name = "c" });
            Files.Add(new MyFile { Name = "d" }); 
        } 
    }
}


David Veeneman
www.veeneman.com

GeneralRe: Editing items in a bound ListBox? Pin
ABitSmart25-Mar-09 5:40
ABitSmart25-Mar-09 5:40 
GeneralRe: Editing items in a bound ListBox? Pin
Member 367392230-Jun-09 20:50
Member 367392230-Jun-09 20:50 
GeneralRe: Editing items in a bound ListBox? Pin
ABitSmart30-Jun-09 20:56
ABitSmart30-Jun-09 20:56 
GeneralRe: Editing items in a bound ListBox? Pin
Member 367392230-Jun-09 21:00
Member 367392230-Jun-09 21:00 
GeneralRe: Editing items in a bound ListBox? Pin
ABitSmart30-Jun-09 21:21
ABitSmart30-Jun-09 21:21 
GeneralRe: Editing items in a bound ListBox? Pin
Member 367392230-Jun-09 21:34
Member 367392230-Jun-09 21:34 
GeneralRe: Editing items in a bound ListBox? Pin
ABitSmart30-Jun-09 21:37
ABitSmart30-Jun-09 21:37 
GeneralRe: Editing items in a bound ListBox? Pin
Member 367392230-Jun-09 22:45
Member 367392230-Jun-09 22:45 
GeneralRe: Editing items in a bound ListBox? Pin
Member 367392230-Jun-09 21:05
Member 367392230-Jun-09 21:05 
GeneralRe: Editing items in a bound ListBox? Pin
ABitSmart30-Jun-09 21:35
ABitSmart30-Jun-09 21:35 
GeneralRe: Editing items in a bound ListBox? Pin
Member 367392230-Jun-09 20:56
Member 367392230-Jun-09 20:56 
QuestionDatabinding textbox to double Pin
ErikZ24-Mar-09 2:46
ErikZ24-Mar-09 2:46 
AnswerRe: Databinding textbox to double Pin
Pete O'Hanlon24-Mar-09 3:56
mvePete O'Hanlon24-Mar-09 3:56 
GeneralRe: Databinding textbox to double Pin
ErikZ24-Mar-09 4:01
ErikZ24-Mar-09 4:01 
GeneralRe: Databinding textbox to double Pin
Pete O'Hanlon24-Mar-09 4:18
mvePete O'Hanlon24-Mar-09 4:18 
GeneralRe: Databinding textbox to double Pin
ErikZ24-Mar-09 20:06
ErikZ24-Mar-09 20:06 
Questionsilverlight and dlls Pin
VCsamir24-Mar-09 2:24
VCsamir24-Mar-09 2:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.