c# - Label DataTemplate depending on selected item -


Based on what type of item I have selected in the tree view, I want to use different data templates < / P>

XML

  & lt; Tree View Name = "SourceDuments List" Item Source = "{Binding Sourcedments}" & gt; & Lt; TreeView.Resources & gt; & Lt; Hierarchical dataTypeplate dataType = "{x: type docom: document}" item source = "{binding block}" & gt; & Lt; Text block text = "{binding filename}" /> & Lt; / HierarchicalDataTemplate & gt; & Lt; /TreeView.Resources> & Lt; / TreeView & gt; & Lt; Label name = "description labels" datacentext = "{binding element name = source document list, path = selected etam}" & gt; & Lt; Label.Resources & gt; & Lt; DataTemplate x: Key = "DocumentTemplate" datatype = "{x: type docom: document}" & gt; & Lt; Text block text = "{binding description}" /> & Lt; / DataTemplate & gt; & Lt; /Label.Resources> & Lt; / Labels & gt;  

In my understanding, the description in the label will be shown only if someone has a document -type Unfortunately, the item has been selected in TreeView, this is not the case. It does not display anything, even if I select in the trim.

Tree Whe also works well with its existing model.

You provide a key, this means that the template can not be fully implemented .

  & lt; Window x: orbit = "wpfApplication10.MainWindow" xmlns = "http: //schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns: x = "http://schemas.microsoft.com/winfx/ 2006 / xaml "xmlns: local =" clr-namespace: WpfApplication10 "heading =" main window "height =" 350 "width =" 525 "& gt; & Lt; Grid & gt; & Lt; Grid.RowDefinitions & gt; & Lt; RowDefinition / & gt; & Lt; RowDefinition / & gt; & Lt; /Grid.RowDefinitions> & Lt; TreeView ItemsSource = "{Binding}" name = "lst" /> & Lt; Label grid Rau = "1" content = "{binding element name = lst, path = chosen item}" & gt; & Lt; Label.Resources & gt; & Lt; DataTemplate DataType = "{x: type local: class 1}" & gt; & Lt; Text box text = "{binding Foo}" /> & Lt; / DataTemplate & gt; & Lt; /Label.Resources> & Lt; / Labels & gt; & Lt; / Grid & gt; & Lt; / Window & gt;  

The above code works like a charm


Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -