How to get updated automatically WPF TreeViewItems with values based on .Net class properties?
- by ProgrammerManiac
Good morning.
I have a class with data derived from InotifyPropertyChange. The data come from a background thread, which searches for files with certain extension in certain locations. Public property of the class reacts to an event OnPropertyChange by updating data in a separate thread. Besides, there are described in XAML TreeView, based on HierarhicalDataTemplates. Each TextBlock inside templates supplied ItemsSource = "{Binding FoundFilePaths, Mode = OneWay, NotifyOnTargetUpdated = True}".
enter code here
<HierarchicalDataTemplate DataType = "{x:Type lightvedo:FilesInfoStore}" ItemsSource="{Binding FoundFilePaths, Mode=OneWay, NotifyOnTargetUpdated=True}">
<!--????? ??????????? ???? ??????-->
<StackPanel x:Name ="TreeNodeStackPanel" Orientation="Horizontal">
<TextBlock Margin="5,5,5,5" TargetUpdated="TextBlockExtensions_TargetUpdated">
<TextBlock.Text>
<MultiBinding StringFormat="Files with Extension {0}">
<Binding Path="FileExtension"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<Button x:Name="OpenFolderForThisFiles" Click="OnOpenFolderForThisFiles_Click" Margin="5, 3, 5, 3" Width="22" Background="Transparent" BorderBrush="Transparent" BorderThickness="0.5">
<Image Source="images\Folder.png" Height="16" Width="20" >
</Image>
</Button>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate DataType="{x:Type lightvedo:FilePathsStore}">
<TextBlock Text="{Binding FilePaths, Mode=OneWay, NotifyOnTargetUpdated=True}" TargetUpdated="OnTreeViewNodeChildren_Update" />
</HierarchicalDataTemplate>
</TreeView.Resources>
<TreeView.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform AngleX="-0.083"/>
<RotateTransform/>
<TranslateTransform X="-0.249"/>
</TransformGroup>
</TreeView.RenderTransform>
<TreeView.BorderBrush>
<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
<GradientStop Color="#FF74591F" Offset="0" />
<GradientStop Color="#FF9F7721" Offset="1" />
<GradientStop Color="#FFD9B972" Offset="0.49" />
</LinearGradientBrush>
</TreeView.BorderBrush>
</TreeView>
Q: Why is the data from a class derived from INotifyPropertyChange does not affect the display of tree items. Do I understand: The interface will make INotifyPropertyChange be automatically redrawn TreeViewItems or do I need to manually carry out this operation? Currently TreeViewItems not updated and PropertyChamged always null. A feeling that no subscribers to the event OnPropertyChanged.