Note that there are some explanatory texts on larger screens.

plurals
  1. POSilverlight Treeview inline HierarchicalDataTemplate binding issue
    primarykey
    data
    text
    <p>I have MyCollection of MyPOCO object (that has two string properties).</p> <p>When I try to implement a HierarchicalDataTemplate into a treeview the binding is not working, I get the class name.</p> <p>I know that if i take out the datatemplate from the control everything works fine but i am interested to see why this example is not working.</p> <pre><code>&lt;Grid x:Name="LayoutRoot" Background="White" DataContext="{Binding Source={StaticResource testVM}}"&gt; &lt;sdk:TreeView Margin="8,8,8,111" ItemsSource="{Binding MyCollection}"&gt; &lt;sdk:HierarchicalDataTemplate ItemsSource="{Binding MyPOCO}"&gt; &lt;sdk:HierarchicalDataTemplate.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel&gt; &lt;TextBlock Text="{Binding Property1}"/&gt; &lt;TextBlock Text="{Binding Property2}"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/sdk:HierarchicalDataTemplate.ItemTemplate&gt; &lt;/sdk:HierarchicalDataTemplate&gt; &lt;/sdk:TreeView&gt; &lt;/Grid&gt; </code></pre> <p>Here is the ViewModel also.</p> <pre><code>namespace MyPOCProject </code></pre> <p>{ public class MyPOCO { private string property1;</p> <pre><code> public string Property1 { get { return property1; } set { property1 = value; } } private string property2; public string Property2 { get { return property2; } set { property2 = value; } } public MyPOCO(string p1, string p2) { property1 = p1; property2 = p2; } } public class MyViewModel : INotifyPropertyChanged { private ObservableCollection&lt;MyPOCO&gt; myCollection; public ObservableCollection&lt;MyPOCO&gt; MyCollection { get { return myCollection; } set { myCollection = value; RaisePropertyChanged("MyCollection"); } } public MyViewModel() { MyPOCO _poco1 = new MyPOCO("aaa1", "bbb1"); MyPOCO _poco2 = new MyPOCO("aaa2", "bbb2"); MyPOCO _poco3 = new MyPOCO("aaa3", "bbb3"); MyCollection = new ObservableCollection&lt;MyPOCO&gt;() { _poco1, _poco2, _poco3 }; } public event PropertyChangedEventHandler PropertyChanged; private void RaisePropertyChanged(string propertyName) { if (this.PropertyChanged != null) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } </code></pre> <p>}</p> <p>So what am I doing wrong?</p> <p>AGAIN ... I am interested in this particular example. I want to know what's wrong with this example and why.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload