[英]CommonStates not triggered automatically
我正在嘗試使用CommonStates
來設置我的用戶控件的動畫。 我嘗試了以下方法:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard>
<ColorAnimationUsingKeyFrames Storyboard.TargetName="circle"
Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)"
EnableDependentAnimation="True">
<LinearColorKeyFrame Value="Red"
KeyTime="0:0:0.02" />
</ColorAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Ellipse x:Name="circle"
Height="280"
Width="280"
Fill="Green" />
</Grid>
我可以通過手動調用UpdateStates(true)
來產生更改,但是請參考文檔,共同狀態應自動觸發。
知道我做錯了什么嗎?
一些控件定義了視覺狀態,並在其實現中進行切換,例如Button
或Checkbox
。 在這種情況下,這些狀態在此處的文檔中列出。 不幸的是Grid
並不是其中之一,因此如果您想在其中使用類似的行為,則需要添加事件處理程序並手動使用GoToState
。 您還可以從Grid
創建一個自定義派生類,以使此行為可重復使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.