2012-09-10 28 views
2

我有一個可以依賴於視圖模型屬性(如改變一個按鈕的結果值窗口的左側或右側會出現一個控制單擊別處UI)。我使用DataTriggers來實現這一定位:如何淡入時的Horizo​​ntalAlignment改變

<DataTrigger Binding="{Binding ShowOnLeft}" Value="True"> 
    <Setter Property="HorizontalAlignment" Value="Left"/> 
</DataTrigger> 
<DataTrigger Binding="{Binding ShowOnLeft}" Value="False"> 
    <Setter Property="HorizontalAlignment" Value="Right"/> 
</DataTrigger> 

我現在想在當它的位置改變控制褪色,所以我加了這些觸發器: -

<Trigger Property="HorizontalAlignment" Value="Left"> 
    <Trigger.EnterActions> 
     <BeginStoryboard> 
      <Storyboard> 
       <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="0.8" Duration="0:0:0.2"/> 
      </Storyboard> 
     </BeginStoryboard> 
    </Trigger.EnterActions> 
</Trigger> 

<Trigger Property="HorizontalAlignment" Value="Right"> 
    <Trigger.EnterActions> 
     <BeginStoryboard> 
      <Storyboard> 
       <DoubleAnimation Storyboard.TargetProperty="Opacity" From="0.0" To="0.8" Duration="0:0:0.2"/> 
      </Storyboard> 
     </BeginStoryboard> 
    </Trigger.EnterActions> 
</Trigger> 

但是它產生一些奇怪的結果。淡入淡出效果在第一次Horizo​​ntalAlignment變爲「左」時起作用,但在隨後的嘗試中不起作用。但是,每次Horizo​​ntalAlignment更改爲「正確」時,淡入淡出都會很愉快。部分似乎是觸發順序 - 如果我交換兩個觸發器,則會發生相反的情況(淡入淡出僅在第一次將Horizo​​ntalAlignment設置爲「右」時起作用,但每次都對「左」起作用)。

我在做什麼錯?

回答

1

也許是瘋狂的猜測,但前段時間我有過類似的(不需要的)行爲。最後,我已將DoubleAnimation的屬性FillBehavior設置爲Stop(默認值爲HoldEnd)。

Read this瞭解關於此屬性/枚舉的更多信息。

+0

這個伎倆!非常感謝。 –

相關問題