user2268507
user2268507

Reputation:

Bind ControlTemplateTrigger to TextBlock property

I am trying to change the TextBlock text colour whenever the Button is highlighted.

However, I don't know how to bind the ControlTemplate.Trigger to the TextBlock Foreground. I tried giving the TextBlock a Name and then using TargetName in Setter but it said that the name wasn't recognised.

<Button Name="Home" HorizontalAlignment="Left" Width="75" Click="Button_Click_Home" Background="#FF252525" BorderThickness="5">
<Button.Content>
    <Grid HorizontalAlignment="Center" VerticalAlignment="Bottom">
        <TextBlock  FontFamily="/VideoManager;component/#Myriad Pro" FontSize="13.333" Foreground="White" Text="Home"></TextBlock>
    </Grid>
</Button.Content>
<Button.Template>
    <ControlTemplate TargetType="{x:Type Button}">
        <ContentPresenter />
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Foreground" Value="#FF360A0A" /> // What to put here..
            </Trigger>
        </ControlTemplate.Triggers> 
    </ControlTemplate>
</Button.Template>

Upvotes: 0

Views: 66

Answers (1)

safi
safi

Reputation: 879

this is going to help you, but it has a lot of loss, so i suggest to you to read more about Styles And Templates

<Button Name="Home" HorizontalAlignment="Left" Width="75" Background="#FF252525" BorderThickness="5">
    <Button.Content>
        <Grid HorizontalAlignment="Center" VerticalAlignment="Bottom">
            <TextBlock  FontFamily="/VideoManager;component/#Myriad Pro" FontSize="13.333" Text="Home"></TextBlock>
        </Grid>
    </Button.Content>
    <Button.Template>
        <ControlTemplate TargetType="{x:Type Button}">
            <Border Background="{TemplateBinding Background}">
                <ContentPresenter />
            </Border>
            <ControlTemplate.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Foreground" Value="Yellow" />
                    <Setter Property="Background" Value="Red" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Button.Template>
</Button>

Upvotes: 1

Related Questions