A.D. A.D. - 2 months ago 16
C# Question

XAML trigger not triggering

do you see anything wrong with this trigger?

<Border Margin="2" BorderBrush="#6593CF" BorderThickness="1.5" >
<Border.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding IsCreating, UpdateSourceTrigger=PropertyChanged}" Value="true">
<Setter Property="Border.BorderBrush" Value="Lime"/>
<Setter Property="Border.BorderThickness" Value="3" />
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>

</Border>


It is bound to this property:

private bool _IsCreating = false;
public bool IsCreating
{
get
{
return _IsCreating;
}
set
{
if (_IsCreating == value)
{
return;
}
_IsCreating = value;
RaisePropertyChanged("IsCreating");
}
}


When I set IsCreating = true, the style does not update.

Answer

You have set BorderBrush and BorderThinkness inline on your border. Inline declaration has quite hight precedence and override your trigger. Remove your inline declaration from border and move it to trigger:

<Border Margin="2">
    <Border.Style>
        <Style TargetType="{x:Type Border}">
            <Style.Triggers>
                <DataTrigger
                    Binding="{Binding Path=DataContext.IsCreating, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                    Value="true">
                    <Setter Property="BorderBrush" Value="Lime" />
                    <Setter Property="BorderThickness" Value="3" />
                </DataTrigger>
                <DataTrigger
                    Binding="{Binding Path=DataContext.IsCreating, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                    Value="false">
                    <Setter Property="BorderBrush" Value="#6593CF" />
                    <Setter Property="BorderThickness" Value="1.5" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Style>
    <CheckBox IsChecked="{Binding IsCreating}" />
</Border>
Comments