Click here to Skip to main content
15,895,827 members
Home / Discussions / WPF
   

WPF

 
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 
AnswerRe: Q1: Populate TreeView from source (C#) Pin
Pete O'Hanlon1-Jul-11 0:05
mvePete O'Hanlon1-Jul-11 0:05 
In order to use the TreeView simply in WPF, it's important to understand that a tree represents a hierarchy of information. Another important concept to remember is that you are going to represent the hierarchy by changing the template of the control to display the data in a different fashion. I've deliberately used those words because the thing I want you to remember is that you can change the appearance of data using a DataTemplate, and that as you have a hierarchy of data in the TreeView, it takes a HierarchicalDataTemplate (even though you are only using one level of data, it has to cater for multiple levels).

So, we have a HierarchicalDataTemplate - how do we actually code this in our XAML? Well, we need to apply this to the template for each item (or the ItemTemplate), so you would add something in that represented a single item. In this case, let's use a TextBlock. This would look like:
XML
<TextBlock Text="{Binding Name}" />
That's all we need to do to actually bind to the name, but where do we put this? Well, we know that we need to add it into a HierarchicalDataTemplate, so let's add that into our TreeView. It looks like this:
XML
<TreeView Name="tvTree">
  <TreeView.ItemTemplate>
    <HierarchicalDataTemplate DataType="{x:Type local:Person}">
      <Grid>
        <TextBlock Text="{Binding Name}" />
      </Grid>
    </HierarchicalDataTemplate>
  </TreeView.ItemTemplate>
</TreeView>
Now, you might be wondering why we put a DataType against the HierarchicalDataTemplate. Well, as it's a DataTemplate and there may be multiple different types of data under the tree nodes, the DataType tells WPF which particular type of data to render this TreeView out against. This allows you to build an incredibly complex hierarchy of data in the TreeView, and yet have small self-contained DataTemplate elements reshaping the data easily (don't forget to add a namespace reference so that it knows where to pick Person up from).

I hope this helps.

Forgive your enemies - it messes with their heads


My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility


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
mvePete 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
mvePete 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
mvePete 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 
GeneralRe: Create event in UserControl Pin
Mark Salsbery2-Jul-11 6:19
Mark Salsbery2-Jul-11 6:19 

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.