2011-08-16 17 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> 

該解決方案完美地工作。只是想我會分享。