I have a datatemplate that displays buttons in a stackpanel, whenever a user clicks at the button, the button is said to glow, so I have written the necessary datatrigger in the template and a boolean condition in the property that I'm binding too. Here are the details below
<DataTemplate x:Key="ActionItemsTemplate" DataType="ActionItemViewModel">
<ItemsControl IsTabStop="False" ItemsSource="{Binding}" Margin="6,2">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button x:Name="ActionButton" Command="{Binding Path=Command }" Content="{Binding Path=DisplayName}" Style="{DynamicResource HeaderButton}"/>
<!-- Set special values for Selected Item -->
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding IsSelected}" Value="True">
<Setter TargetName="ActionButton" Property="Style" Value="{DynamicResource MainWindowSelectedButton}"/>
<!--Command="{Binding Path=Command}" Content="{Binding Path=DisplayName}"-->
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
I have implemented the Inotifypropertychanged interface and the Property ActionItems returns an ObservableCollection.
The Problem: When I change the observablecollection and call the INotifyPropertyChanged event, it is not reflected to the datatemplate directly just by altering the property, but if I re-assgn the object with itself, it works perfectly
e.g
void Test1()
{
_commands[0].IsSelected = !_commands[0].IsSelected;
_commands[0] = _commands[0]; // Does not work If this line is commented out
ActionItems = _commands;
}
I wonder what could the problem be?
Edit: I see that the problem could be with the databinding in this case,
I have arrived at a similar problem now where I have bound a IsExpanded property of the Expander control to a bool property, inside a TabPanel, when I toggle the bool property, the value is changed behind, but not reflected in the display, but suppose I change tabs and come back, I see the change has taken place, did find a similar problem here
And again I wonder what could the problem be ( but narrowed it somewhat :) )
Edit 2: Solution for second Problem: I found that the OnPropertyChanged Event of the INotifyPropertyChanged Interface needs to be called, whenever a programmatic update on the IsExpanded property is updated,
as for Original Problem, this does not seem to be the case, and I'm still trying to figure out what could the problem be :)