Wpf 如何为IsMouseOver触发器的ControlTemplate内的按钮设置内容

Wpf 如何为IsMouseOver触发器的ControlTemplate内的按钮设置内容,wpf,button,triggers,controltemplate,Wpf,Button,Triggers,Controltemplate,我正在更改按钮的ControlTemplate,并且成功地更改了视觉外观,但是,当我尝试在ControlTemplate内的IsMouseOver触发器上更改按钮的内容时,它不起作用。下面是我的xaml: <Window x:Class="WpfApplication1.Window2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.micr

我正在更改按钮的ControlTemplate,并且成功地更改了视觉外观,但是,当我尝试在ControlTemplate内的IsMouseOver触发器上更改按钮的内容时,它不起作用。下面是我的xaml:

<Window x:Class="WpfApplication1.Window2"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="300" Width="300">

  <Window.Resources>        

    <ControlTemplate x:Key="ngButton" TargetType="Button">
        <Grid>
            <Border Name="templateBorder" BorderThickness="2" Background="Blue" />


            <Ellipse  Name="el2" Margin="10,10,10,10" Fill="Magenta" />

            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" Content="{TemplateBinding Content}"/>
        </Grid>


        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="templateBorder" Property="Background" Value="DarkRed" />
                <Setter TargetName="el2" Property="Fill" Value="Green" />
                <Setter Property="Content">
                    <Setter.Value>
                            <TextBlock Text="Mouse is over" />
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter TargetName="templateBorder" Property="Background" Value="LightBlue" />
                <Setter TargetName="templateBorder" Property="BorderBrush" Value="DarkKhaki" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>


</Window.Resources>

<Grid>

    <Button Content="Hello World" Template="{StaticResource ngButton}" Name="ngButtonHello" Height="200" Width="200"/>

</Grid> 

感谢您的帮助。

请阅读:本地值(“示例中的“Hello World”)始终优先于触发器设置的值


在样式中设置原始内容属性,或者使用本地值属性中的转换器将
IsMouseOver
转换为特定字符串。

太好了。谢谢你的帮助。