DataTrigger and HeaderStringFormat problem...

Feb 12, 2009 at 7:08 PM

I have a Tab control that is bound to a Documents collection in the view model.
Each document have an IsDirty property that when set to true, I want the title of the document to have for example an *.
I know that I can put this logic in the view model, but I want tp put it in the view instead...
However to solve my problem I use a DataTrigger to monitor the IsDirty property and I use a HeaderStringFormat to append an * to the title.
Here is the code:

<Style x:Key="MyTabItemStyle" TargetType="{x:Type TabItem}">
  <DataTrigger Binding="{Binding IsDirty}" Value="True">
   <Setter Property="Header" Value="{Binding DisplayName}"/>
   <Setter Property="HeaderStringFormat" Value="*{0}"/>
  <DataTrigger Binding="{Binding IsDirty}" Value="False">
   <Setter Property="Header" Value="{Binding DisplayName}"/>
   <Setter Property="HeaderStringFormat" Value=""/>

The problem is that the initial value of IsDirty is false, so the document title will display correctly,
but after IsDirty is set to true, the title of the document does not change !!!

If I remove the last setter property (<Setter Property="HeaderStringFormat" Value=""/>), an * will be appended to the title of the document
when it is Dirty, but will not change when IsDirty become false.

So, this lead me to think that the first value of HeaderStringFormat property is the effective value, and any different value later
will not have any effect...

so how I can solve my problem ??

Feb 13, 2009 at 6:04 AM
Does your Documents collection implement INotifyPropertyChanged?
Feb 14, 2009 at 8:42 PM
Yes it does.