1

我是一名使用 Expression Blend 4 的设计师,我们的环境是 .NET 3.5。

这个问题对你们来说可能很简单,但它给我带来了很大的问题。

我需要对按钮应用交互,当按钮启用时将触发状态。

在按钮上,开发人员有一个与 IsEnabled 属性关联的布尔值。我必须为 EventTrigger 提供一个 EventName,而我唯一能想到的就是 IsEnabledChanged。但是,当我运行该应用程序时,它什么也不做。

如何告诉触发器查找按钮 IsEnabled 属性的布尔值的变化?

这是代码:

<Button x:Name="SaveButton"
        Command="{Binding SaveCommand}" 
        IsEnabled="{Binding IsSaveAllowedBool}">

<i:Interaction.Triggers>
   <i:EventTrigger EventName="IsEnabledChanged">
        <ic:GoToStateAction StateName="MyState"/>
   </i:EventTrigger>
</i:Interaction.Triggers>

</Button>
4

1 回答 1

2

我找到了解决我的问题的方法。

我将 a 包裹在我试图根据布尔值出现/消失ContentControl的元素周围(我这样做是为了修改 a -元素没有与之关联的)BorderControlTemplateBorderControlTemplate

IsEnabled然后我将 的属性绑定ContentControl到开发人员拥有的同一个布尔值上。我将 的 修改为ControlTemplate当布尔值更改时ContentControlTrigger触发。

这是代码:

<Style x:Key="MyContentControl" TargetType="{x:Type ContentControl}">
  <Setter Property="Template">
    <Setter.Value>
      <ControlTemplate TargetType="{x:Type ContentControl}">
        <ContentPresenter/>
        <ControlTemplate.Triggers>
          <Trigger Property="IsEnabled" Value="False">
            <Setter Property="Visibility" Value="Collapsed"/>
          </Trigger>
        </ControlTemplate.Triggers>
      </ControlTemplate>
    </Setter.Value>
  </Setter>
</Style>

<ContentControl Style="{DynamicResource MyContentControl}" 
                IsEnabled="{Binding IsSaveAllowedBool}">
     <!--  ALL MY CONTENT -->
</ContentControl>

该解决方案完美运行。只是想我会分享。

于 2011-08-17T15:00:56.147 回答