【问题标题】:Bind ControlTemplateTrigger to TextBlock property将 ControlTemplateTrigger 绑定到 TextBlock 属性
【发布时间】:2015-01-19 00:33:02
【问题描述】:

每当Button 突出显示时,我都会尝试更改TextBlock 文本颜色。

但是,我不知道如何将ControlTemplate.Trigger 绑定到TextBlock Foreground。我尝试给TextBlock 一个Name,然后在Setter 中使用TargetName,但它说这个名字没有被识别。

<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>

【问题讨论】:

  • 解释你想要什么
  • @safi 在第一行。

标签: c# wpf button triggers controltemplate


【解决方案1】:

这会对你有所帮助,但它有很多损失,所以我建议你阅读更多关于样式和模板的内容

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-18
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多