【问题标题】:Apply Style to Polygon将样式应用于多边形
【发布时间】:2012-06-26 10:36:30
【问题描述】:

我想将以下Style 应用到我的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>

当光标在我的多边形上时,我想要一个黑色笔触,当光标不在我的多边形上时,我不想看到任何东西。为什么这种风格不起作用(我什么都没看到)?

编辑:

这是我的多边形:

var pol = new Polygon();

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

【问题讨论】:

  • 你能发布一个示例多边形吗?
  • @nemesv 我添加了用于创建多边形的代码。

标签: c# wpf triggers styles polygon


【解决方案1】:

不要将Shape.Fill 设置为Null,试试这个:

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

【讨论】:

    猜你喜欢
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-15
    • 2019-08-12
    • 1970-01-01
    • 2011-06-08
    相关资源
    最近更新 更多