You cannot use Setters
like that, if you use this kind of notation the engine will look for an attached property, or if no Style.TargetType
was set for a property on the type before the dot.
The easiest thing to do is probably applying a style to the polygon itself and using a DataTrigger
which binds to the Canvas
so you can trigger on its properties.
<Polygon Points="11,1 16,6 16,16 11,21" Name="polygon">
<Polygon.Fill>
<SolidColorBrush Color="#EEEEEE"/>
</Polygon.Fill>
<Polygon.Style>
<Style TargetType="{x:Type Polygon}">
<Style.Triggers>
<DataTrigger
Binding="{Binding Path=IsMouseOver,
RelativeSource={RelativeSource
AncestorType={x:Type Canvas}}}"
Value="True">
<Setter Property="Stroke" Value="Red"/>
</DataTrigger>
</Style.Triggers>
</Style>
<Polygon.Style>
</Polygon>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…