Note that there are some explanatory texts on larger screens.

plurals
  1. PORefreshing UI with databind in WPF
    primarykey
    data
    text
    <p>I have a 3 layer deep treeview,</p> <pre> -MAIN ->:SUB1 >:SUB2 >:SUB2 -X:SUB1 X:SUB2 SUB1 SUB1 </pre> <p>where, > and X represent graphics denoting the status of that specific item (determined from backend).</p> <p>I'm using an Observable Dictionary to bind to this tree (and it has an ICollectionChanged event). The structure is like this:</p> <pre> <code> ObservableDictionary&lt;string,CustomClass&gt; mainitems; public class CustomClass{ ObservableDictionary&lt;string, InnerClass&gt; sub1item; // Bunch of properties and methods in this class // INotify not implemented } public class InnerClass{ // Bunch of properties and methods in this class // INotify not implemented public SomeEnum Status{ get{ return this.status; } } } </code> </pre> <p>The graphics, mentioned above, are binded using a custom converter which converts the Status enum to a path so that it can be binded (ie. &lt;img source="{Binding Path=something, Converter={StaticResource someconverter}, Mode=OneWay" /&gt; ).</p> <p><strong>QUESTION:</strong></p> <p>My problem is, when I update the CustomClass's sub1item dictionary with new statuses, it doesn't update it in the UI. I think implementing INotify stuff might work but I don't know where I need to update it and exactly how to do so.</p> <p><strong>Edit:</strong> My XAML template for the treeview is as follows:</p> <pre> <code> &lt;TreeView Name="tvInstance" ItemsSource="{Binding}" TreeViewItem.Selected="tviSelected" IsTextSearchEnabled="True"&gt; &lt;TreeView.ItemContainerStyle&gt; &lt;Style&gt; &lt;Setter Property="TreeViewItem.IsExpanded" Value="{Binding Path=Value.Expanded, Mode=TwoWay}" /&gt; &lt;/Style&gt; &lt;/TreeView.ItemContainerStyle&gt; &lt;TreeView.ItemTemplate&gt; &lt;HierarchicalDataTemplate ItemsSource="{Binding Path=Value.CustomClass}" ItemContainerStyle="{x:Null}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Label Content="{Binding Path=Key}"/&gt; &lt;/StackPanel&gt; &lt;HierarchicalDataTemplate.ItemTemplate&gt; &lt;HierarchicalDataTemplate ItemsSource="{Binding Path=Value.AnotherClass}"&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Source="{Binding Path=Value.Status, Converter={StaticResource convertstatus} }" Width="10" Height="10"/&gt; &lt;Label Content="{Binding Path=Key}" /&gt; &lt;/StackPanel&gt; &lt;HierarchicalDataTemplate.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;Image Source="{Binding Path=Value, Converter={StaticResource convertstatus} }" Width="10" Height="10"/&gt; &lt;Label Content="{Binding Path=Key}" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/HierarchicalDataTemplate.ItemTemplate&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/HierarchicalDataTemplate.ItemTemplate&gt; &lt;/HierarchicalDataTemplate&gt; &lt;/TreeView.ItemTemplate&gt; &lt;/TreeView&gt; </code> </pre> <p>EDIT: After adding all INotifyProperty events in my mainclass, my CustomClass, and my InnerClass, it still doesn't work. I'm using the Dr. WPF version of ObservableDictionary (and using a dictionary is crucial to my application since I need to do lots of lookups). Help!</p> <h1>Epilogue</h1> <p>The answers in this page are correct in that INotifyPropertyChanged needs to be implemented on properties I want updated in the UI.</p> <p>I found that binding the dictionary was too much trouble so I kept both an ObservableCollection and a Dictionary. I used the dictionary for lookup and the collection for binding (since both use the same reference to the object, removing was easy with the collection and the only O(n) operation).</p> <p>With regards to updating in the UI, please refer to the other posts on this page.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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