2011-08-16 15 views
1

我是一位使用Expression Blend 4的设计师,我们的环境是.NET 3.5。Expression Blend Interaction:如何设置触发器以查找Button的IsEnabled值?

这个问题对你们来说可能很简单,但是这对我造成了相当大的问题。

我需要将交互应用于一个按钮,该按钮将在启用按钮时触发一个状态。

在该按钮上,开发人员具有与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> 

回答

2

我找到了解决我的问题。

我包裹ContentControlBorder元素,我试图让显示/基础上,布尔值消失(我为了修改ControlTemplate这样做 - 在Border元素没有与之相关联的ControlTemplate)围绕

然后,我将ContentControlIsEnabled属性绑定到开发者所拥有的相同bool。我将ContentControlControlTemplate修改为Trigger,当布尔值更改时会触发。

下面是代码:

<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> 

该解决方案完美地工作。只是想我会分享。