0

I'm trying to change the style of a button as well as the style of a textblock included in the button via a binding without success. I want to get something like this:

enter image description hereenter image description here

I want change the TextBlock foreground color and the Button BorderThickness according to the binding.

Here is my code :

<Button Name="WeldHistory"
Margin="20,0,20,0"
VerticalAlignment="Stretch"
Height="auto"
Background="{x:Null}"
BorderBrush="{StaticResource RedPolysoudeNormalBrush}"
BorderThickness="0 0 0 3"
Command="{Binding ScreenWeldHistoryCommand}" >
<Button.ContentTemplate>
    <DataTemplate>
        <TextBlock Text="{x:Static lang:UI_Text.SCREEN_PROGRAM_LIBRARY}" Typography.Capitals="AllSmallCaps" Typography.CapitalSpacing="True">
            <TextBlock.Style>
                <Style TargetType="{x:Type TextBlock}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsWeldHistoryActive}" Value="False">
                            <Setter Property="Foreground" Value="red"/>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
    </DataTemplate>
</Button.ContentTemplate>

1 Answer 1

1

I believe the problem should be with the Binding which you are making with IsWeldHistoryActive. Can you try with binding to the Button's DataContext ?

<TextBlock.Style>
    <Style TargetType="{x:Type TextBlock}">
        <Style.Triggers>
            <DataTrigger Binding="{Binding DataContext.IsWeldHistoryActive, 
                                   RelativeSource={RelativeSource AncestorType=Button, 
                                                   Mode=FindAncestor}}" 
                         Value="False">
                <Setter Property="Foreground" Value="Red"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</TextBlock.Style>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.