Expression Blend Interaction: How to set Trigger to Look for IsEnabled Value of Button?

瘦欲@ 提交于 2019-12-11 09:19:08

问题


I am a designer using Expression Blend 4 and our environment is .NET 3.5.

This issue may be simple to you guys, but it is causing me quite a problem.

I need to apply an interaction to a button that will trigger a state when the button becomes enabled.

On the button, the developer has a Boolean value associated with the IsEnabled property. I have to supply the EventTrigger with an EventName, and the only thing that I can think of is IsEnabledChanged. However, when I run the app, this does nothing.

How do I tell the Trigger to look for a change in the Boolean value of the IsEnabled property of the button?

Here is the code:

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

回答1:


I found a solution to my problem.

I wrapped a ContentControl around the Border element that I am trying to make appear/disappear based on the Boolean value (I did this in order to modify a ControlTemplate - the Border element does not have a ControlTemplate associated with it)

Then I bound the IsEnabled property of the ContentControl to the same bool the developer had. I modified the ControlTemplate of the ContentControl to have a Trigger that would fire when the Boolean value changed.

Here is the code:

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

This solution worked perfectly. Just thought I'd share.



来源:https://stackoverflow.com/questions/7084149/expression-blend-interaction-how-to-set-trigger-to-look-for-isenabled-value-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!