In my application, I have a graph (Custom Wpf Panel) with Wpf controls as elements. The elements are custom controls derived from Wpf Control. DataTemplates associate the controls to their view models. The view models collection, "GraphElements" is binded to the itemsControl as shown below.
<ItemsControl x:Name="PART_GraphItemsControl" Grid.Column="1"
VerticalAlignment="Stretch"
HorizontalAlignment="Left"
ItemsSource="{Binding Path=GraphElements}"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:GraphDesignerPanel HorizontalAlignment="Stretch"
VerticalAlignment="Top" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
The elements in the graph can vary from 2 to 500. Under certain mode of the application, the elements display their value. To display the value, the ViewModel for the element fires the INotifyPropertyChanged.PropertyChanged("VariableValue")
Issue: When i have 100+ elements in the graph, each elements view model fires INotifyPropertyChanged.PropertyChanged to have the elements value displayed. This calls MeasureOverride 100+ times leading to memory and peformance issues.
How can I reduce the number of MeasureOverride calls?
XAML for Value display for the graph element:
<TextBlock
Text="{Binding Path=VariableValue, StringFormat={}({0})}" Width="60"
FontSize="11" Name="txtBlk">
</TextBlock>
The TextBlock above is collapsed if VariableValue is null
<DataTrigger Binding="{Binding Path=VariableValue}" Value="{x:Null}">
<Setter TargetName="txtBlk" Property="Visibility" Value="Collapsed"/>
</DataTrigger>
UPDATE: The issue is reproducible in the sample at the link given below. Download, build, debug. Once App is opened, set a breakpoint in Window.xaml.cs MeasureOverride. Come back to the App and hit the "Click Me" button. The breakpoint is hit 11 times !.
http://sivainfotech.co.uk/measureoverrideissue.zip
Any ideas greatly appreciated.