Click here to Skip to main content
15,867,308 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Error 13 The type or namespace name 'TimePicker' does not exist in the namespace 'System.Windows.Controls' (are you missing an assembly reference?) Pin
Oludayo Alli19-Aug-11 6:04
Oludayo Alli19-Aug-11 6:04 
QuestionMultiple calls to same wcf service method from Silverlight application Pin
Pankaj Chamria3-Jul-11 23:01
Pankaj Chamria3-Jul-11 23:01 
AnswerRe: Multiple calls to same wcf service method from Silverlight application Pin
Abhinav S4-Jul-11 3:22
Abhinav S4-Jul-11 3:22 
AnswerRe: Multiple calls to same wcf service method from Silverlight application Pin
Mark Salsbery4-Jul-11 8:54
Mark Salsbery4-Jul-11 8:54 
AnswerRe: Multiple calls to same wcf service method from Silverlight application Pin
BobJanova5-Jul-11 0:59
BobJanova5-Jul-11 0:59 
QuestionProblem with DataGrid Rows in WPF Pin
Member 29729921-Jul-11 3:24
Member 29729921-Jul-11 3:24 
AnswerRe: Problem with DataGrid Rows in WPF Pin
Mycroft Holmes2-Jul-11 12:40
professionalMycroft Holmes2-Jul-11 12:40 
QuestionQ1: Populate TreeView from source (C#) Pin
Mc_Topaz30-Jun-11 23:34
Mc_Topaz30-Jun-11 23:34 
I want to populate a TreeView dynamically during runtime of my program.
The WPF TreeView is for me very confusing and I can't really find any easy and simple guide. I hence this thread will be long because I have lot's of questions. Let's take them one by one.

My XAML is just:
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">

    <Grid>
        <TreeView Name="tvTree"></TreeView>
    </Grid>
</Window>


My C# code is:
namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        List<Person> persons;

        public MainWindow()
        {
            InitializeComponent();

            persons = new List<Person>();
            persons.Add(new Person("Person1"));
            persons.Add(new Person("Person2"));
            persons.Add(new Person("Person3"));
            persons.Add(new Person("Person4"));
            persons.Add(new Person("Person5"));

            tvTree.ItemsSource = persons;
        }
    }

    public class Person
    {
        string name;

        public Person(string name)
        {
            this.name = name;
        }

        public string Name
        {
            get { return name; }
        }
    }
}

This will actually populate the TreeView with five TreeViewItems:

WpfApplication1.Person
WpfApplication1.Person
WpfApplication1.Person
WpfApplication1.Person
WpfApplication1.Person

This was somewhat expected since the TreeView read the ToString() method from my Person class.

But can I make the TreeView read the person's name from the Name property instead? I don't want to override the ToString() method to do this. I would like to use the Name property and connect that property to the XAML code.
AnswerRe: Q1: Populate TreeView from source (C#) Pin
Pete O'Hanlon1-Jul-11 0:05
subeditorPete O'Hanlon1-Jul-11 0:05 
QuestionQ2: Implement TreeView with multi level of data Pin
Mc_Topaz1-Jul-11 1:19
Mc_Topaz1-Jul-11 1:19 
AnswerRe: Q2: Implement TreeView with multi level of data Pin
Pete O'Hanlon1-Jul-11 1:30
subeditorPete O'Hanlon1-Jul-11 1:30 
GeneralRe: Q2: Implement TreeView with multi level of data Pin
Mc_Topaz1-Jul-11 2:14
Mc_Topaz1-Jul-11 2:14 
GeneralRe: Q2: Implement TreeView with multi level of data Pin
Pete O'Hanlon1-Jul-11 2:22
subeditorPete O'Hanlon1-Jul-11 2:22 
QuestionQ3: Implement TreeView with two data source classes [modified] Pin
Mc_Topaz3-Jul-11 23:45
Mc_Topaz3-Jul-11 23:45 
QuestionSync call to WCF Methods Pin
NTheOne30-Jun-11 19:03
NTheOne30-Jun-11 19:03 
AnswerRe: Sync call to WCF Methods Pin
Pete O'Hanlon30-Jun-11 21:41
subeditorPete O'Hanlon30-Jun-11 21:41 
QuestionCreate event in UserControl Pin
jadughar30-Jun-11 10:55
jadughar30-Jun-11 10:55 
AnswerRe: Create event in UserControl Pin
Mark Salsbery30-Jun-11 13:43
Mark Salsbery30-Jun-11 13:43 
GeneralRe: Create event in UserControl Pin
jadughar30-Jun-11 21:12
jadughar30-Jun-11 21:12 
GeneralRe: Create event in UserControl Pin
Mark Salsbery1-Jul-11 6:26
Mark Salsbery1-Jul-11 6:26 
GeneralRe: Create event in UserControl Pin
jadughar1-Jul-11 7:59
jadughar1-Jul-11 7:59 
GeneralRe: Create event in UserControl Pin
Mark Salsbery1-Jul-11 8:09
Mark Salsbery1-Jul-11 8:09 
GeneralRe: Create event in UserControl Pin
jadughar1-Jul-11 10:45
jadughar1-Jul-11 10:45 
GeneralRe: Create event in UserControl Pin
Mark Salsbery1-Jul-11 12:04
Mark Salsbery1-Jul-11 12:04 
GeneralRe: Create event in UserControl Pin
jadughar2-Jul-11 0:11
jadughar2-Jul-11 0:11 

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.