开发者

XAML: Why doesn't this trigger work?

I'd like to use a trigger outside a style. Edit: whoops, sorry, it's actually inside开发者_StackOverflow社区 a style for MainWindow, but I want the trigger to apply to the Ellipse and not MainWindow.

<Ellipse Fill="White" StrokeThickness="1" Stroke="Black">
    <Ellipse.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Fill" Value="Yellow"/>
        </Trigger>
    </Ellipse.Triggers>
</Ellipse>

How do I fix the compiler error, which is "Cannot find the static member 'FillProperty' on the type 'MainWindow'"?


you have to put this in style

<Ellipse  StrokeThickness="1" Width="20" Height="20" Stroke="black">
    <Ellipse.Style>
  <Style TargetType="{x:Type Ellipse}">
    <Setter Property="Fill" Value="Red"/>

    <Style.Triggers>
      <Trigger Property="IsMouseOver" Value="true">
        <Setter Property="Fill" Value="green"/>
      </Trigger>
    </Style.Triggers>
  </Style>
</Ellipse.Style>


In direct Triggers you need qualifying type names like so:

<Ellipse Width="100" Height="100">
    <Ellipse.Triggers>
        <Trigger Property="Ellipse.IsMouseOver" Value="True">
            <Setter Property="Ellipse.Fill" Value="Yellow" />
        </Trigger>
    </Ellipse.Triggers>
</Ellipse>

This won't work though since direct triggers only allow EventTriggers, use a Style instead.


Your window doesn't have a property named "Fill" like an Ellipse does. Maybe you mean "Background".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜