views:

248

answers:

1

I have a set of triggers in a XAML form, and for the life of me I can't figure out why one set works, and the other doesn't, despite being bound to the exact same variable.

First, the triggers that do work:

<StackPanel Orientation="Vertical" Margin="25,0,0,0">
    <StackPanel.Style>
        <Style TargetType="{x:Type StackPanel}">
            <Setter Property="IsEnabled" Value="False" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding GorOption.InternalName}" Value="Separator">
                    <Setter Property="IsEnabled" Value="True" />
                </DataTrigger>
            </Style.Triggers>
        </Style> 
    </StackPanel.Style>
</StackPanel>

<StackPanel Orientation="Vertical" Margin="25,0,0,0">
    <StackPanel.Style>
        <Style TargetType="{x:Type StackPanel}">
            <Setter Property="IsEnabled" Value="False" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding GorOption.InternalName}" Value="BubblePoint">
                    <Setter Property="IsEnabled" Value="True" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </StackPanel.Style>
</StackPanel>

This trigger works beautifully. Now, I have a GroupBox and a Label with very similiar triggers that does not work at all. The triggers that don't work:

<GroupBox Header="Recombined Gas" Grid.Row="1" Grid.ColumnSpan="2">
    <GroupBox.Style>                
        <Style TargetType="{x:Type GroupBox}">
            <Setter Property="Header" Value="Recombined Gas" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding GorOption.InternalName}" Value="Separator">
                    <Setter Property="Header" Value="Separator Gas" />
                </DataTrigger>
                <DataTrigger Binding="{Binding GorOption.InternalName}" Value="BubblePoint">
                    <Setter Property="Header" Value="Dissolved Gas" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </GroupBox.Style>
</GroupBox>

And the label trigger that doesn't work:

<Label Content="Reombined GOR" Width="90">
    <Label.Style>
        <Style TargetType="{x:Type Label}">
            <Setter Property="Content" Value="Recombined GOR" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding GorOption.InternalName}" Value="Separator">
                    <Setter Property="Content" Value="Separator GOR" />
                </DataTrigger>
                <DataTrigger Binding="{Binding GorOption.InternalName}" Value="BubblePoint">
                    <Setter Property="Content" Value="Dissolved GOR" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Label.Style>
</Label>

I feel like I am missing something fundamental here, but right now it escapes me. As you can see, all the triggers bind to the same value and trigger on the same options. Is it because I have two DataTrigger blocks trying to bind to the same variable in a single Triggers block? I can't imagine this being an issue, and in fact, I am sure I do this elsewhere. Is it something specific to Label and GroupBox that I am not aware?

A: 

Nevermind, answered this myself two minutes after posting it. I guess it was one of those "need to see it in a different context" problems. I feel like I'm talking to myself...

Anyways, the issue is that when you set a property like Content or Header in the original XAML tag, then try and change that property with a trigger, the trigger is ignored for some reason. I am assuming that this is explained in some archaic WPF document that I haven't seen yet, but it's very confusing until you figure it out.

Matt Holmes