Wpf 这个触发器怎么了?

Wpf 这个触发器怎么了?,wpf,Wpf,我正在学习WPF模板,我正在为一个按钮创建一个模板。我正在使用触发器更改“IsMouseOver”上椭圆的填充属性。当我直接将触发器设置为“Fill”属性时,它就工作了。但是,当我尝试引用特定的SolidColorBrush时,会出现编译错误 这项工作: <ControlTemplate x:Key="GhostButtonTemplate" TargetType="Button"> <Grid> <Ellipse Name=

我正在学习WPF模板,我正在为一个按钮创建一个模板。我正在使用触发器更改“IsMouseOver”上椭圆的填充属性。当我直接将触发器设置为“Fill”属性时,它就工作了。但是,当我尝试引用特定的SolidColorBrush时,会出现编译错误

这项工作:

<ControlTemplate x:Key="GhostButtonTemplate" TargetType="Button">
        <Grid>
            <Ellipse Name="Border" Stroke="DarkGray" Fill="Gray">        
        </Ellipse>
            <ContentPresenter ... />
        </Grid>
    <ControlTemplate.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
        <Setter TargetName="Border" Property="Fill" Value="Black"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

这会导致错误:

<ControlTemplate x:Key="GhostButtonTemplate" TargetType="Button">
        <Grid>
            <Ellipse Name="Border" Stroke="DarkGray">
                <Ellipse.Fill>
                    <SolidColorBrush Color="Gray" x:Name="FillBrush"/>
            </Ellipse.Fill>         
        </Ellipse>
            <ContentPresenter ... />
        </Grid>
    <ControlTemplate.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
        <Setter TargetName="FillBrush" Property="Color" Value="Black"/>
        </Trigger>
    </ControlTemplate.Triggers>
</ControlTemplate>

错误是:

找不到触发器目标 “灌木丛”。(目标必须出现。) 在任何设置器、触发器或 使用它的条件。)


有人能解释为什么第二个案例不起作用吗?谢谢。

您使用椭圆而不是命名画笔 编辑,是的,你知道这个:P

<ControlTemplate x:Key="GhostButtonTemplate" TargetType="Button">
    <Grid>
        <Ellipse Name="Border" Stroke="DarkGray">
            <Ellipse.Fill>
                <SolidColorBrush Color="Gray" x:Name="FillBrush"/>
        </Ellipse.Fill>         
    </Ellipse>
        <ContentPresenter ... />
    </Grid>
<ControlTemplate.Triggers>
    <Trigger Property="IsMouseOver" Value="True">
    <Setter TargetName="Border" Property="Fill" Value="Black"/>
    </Trigger>
</ControlTemplate.Triggers>


比黑色稍微复杂一点的东西怎么样?