尝试在DataTrigger中绑定枚举,为什么不起作用?

9
我希望我的椭圆现在是红色的。 enter image description here
<UserControl x:Class="BenchmarkPlus.PMT.UI.Views.NotificationIndicator"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Models="clr-namespace:BenchmarkPlus.PMT.UI.Models"
             mc:Ignorable="d"
             d:DesignHeight="300"
             d:DesignWidth="300"
             x:Name="root"
             DataContext="{x:Static Models:NotificationType.Error}">
  <Grid>
    <Ellipse>
      <Ellipse.Style>
        <Style TargetType="Ellipse">
          <Setter Property="Fill"
                  Value="Blue" />
          <Style.Triggers>
            <DataTrigger Binding="{Binding}"
                         Value="{x:Static Models:NotificationType.Info}">
              <Setter Property="Fill"
                      Value="Green" />
            </DataTrigger>
            <DataTrigger Binding="{Binding}"
                         Value="{x:Static Models:NotificationType.Error}">
              <Setter Property="Fill"
                      Value="Red" />
            </DataTrigger>
          </Style.Triggers>
        </Style>
      </Ellipse.Style>
    </Ellipse>
  </Grid>
</UserControl>

4
这也适用于运行时吗?我不会相信 GUI 设计师的任何东西。 - H.B.
哦,你说得对...愚蠢的设计师。 - Jon Erickson
我使用了一个枚举类来获取值,并将其绑定到图像源。这是属性事件绑定和枚举器的混合使用。如果没有这个示例,第二部分就不可能实现。谢谢。 - Pimenta
1个回答

2

这似乎在VS2010设计器中无法正常工作,但在VS11中可以。这是切换到VS11 beta的另一个原因:)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接