Nick
Nick

Reputation: 10499

Apply Style to Polygon

I want to apply the following Style to my Polygon:

<Style xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:s="clr-namespace:System;assembly=mscorlib" 
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   TargetType="{x:Type Polygon}">

<Style.Triggers>

    <Trigger Property="Shape.IsMouseOver" Value="True">

        <Setter Property="Shape.Stroke">
            <Setter.Value>
                <SolidColorBrush>#FF000000</SolidColorBrush>
            </Setter.Value>
        </Setter>

        <Setter Property="Shape.StrokeThickness">
            <Setter.Value>
                <s:Double>2</s:Double>
            </Setter.Value>
        </Setter>

    </Trigger>

    <Trigger Property="Shape.IsMouseOver" Value="False">

        <Setter Property="Shape.StrokeThickness">
            <Setter.Value>
                <s:Double>0</s:Double>
            </Setter.Value>
        </Setter>

    </Trigger>

</Style.Triggers>


<Setter Property="Shape.Fill" Value="{x:Null}"/>  

</Style>

When the cursor is over my Polygon I want a Black stroke, when the cursor is not over my Polygon I don't want to see anything. Why this style does not work (I do not see anything)?

Edit:

This is my Polygon:

var pol = new Polygon();

using (FileStream stream = new FileStream("myStyle.xaml", FileMode.Open))
       pol.Style = XamlReader.Load(stream) as Style;

Upvotes: 1

Views: 1157

Answers (1)

gliderkite
gliderkite

Reputation: 8928

Don't set the Shape.Fill to Null, try this instead:

<Setter Property="Shape.Fill" Value="Transparent"/>  

Upvotes: 1

Related Questions