开发者

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

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>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜