DataTrigger not reevaluating after property changes

Posted by frozen on Stack Overflow See other posts from Stack Overflow or by frozen
Published on 2010-03-12T12:03:51Z Indexed on 2010/03/12 12:07 UTC
Read the original article Hit count: 194

Filed under:
|
|

I have a listbox which has its itemssource (this is done in the code behind on as the window is created) databound to an observable collection. The List box then has the following data template assigned against the items:

usercontrol.xaml
...
<ListBox x:Name="communicatorListPhoneControls" ItemContainerStyle="{StaticResource templateForCalls}"/>
...

app.xaml
...
<Style x:Key="templateForCalls" TargetType="{x:Type ListBoxItem}">
<Setter Property="ContentTemplate" Value="{StaticResource templateRinging}"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Path=hasBeenAnswered}" Value="True">
<Setter Property="ContentTemplate" Value="{StaticResource templateAnswered}"/>
</DataTrigger>
</Style.Triggers>
</Style>

...

When the observable collection is updated with an object, this appears in the listbox with the correct initial datatemplate, however when the "hasBeenAnswered" property is set to true (when debugging i can see the collection is correct) the datatrigger does not re-evaluate and then update the listbox to use the correct data template.

I have implemented the INotifyPropertyChanged Event in my object, and if in the template i bind to a value, i can see the value update. Its just that the datatrigger will not re-evaluate and change to the correct template.

I know the datatrigger binding is correct because if i close the window and open it again, it will correctly apply the second datatemplate, because the "hasBeenAnswered" is set to True.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about datatemplate