我試圖在Silverlight中創建模板/自定義控件。Silverlight:如何爲模板/自定義控件創建VisualState
基本控件可以是System.Windows.Controls.Button
。按鈕具有以下可視狀態:
<vsm:VisualStateManager.VisualStateGroups>
<!--Define the states for the common states. The states in a
VisualStateGroup are mutually exclusive to each other.-->
<vsm:VisualStateGroup x:Name="CommonStates">
<!--Define the VisualStates in this VistualStateGroup.-->
<vsm:VisualState x:Name="Normal"/>
<vsm:VisualState x:Name="MouseOver" />
<vsm:VisualState x:Name="Pressed" />
<vsm:VisualState x:Name="Disabled" />
</vsm:VisualStateGroup>
<!--Define the states for the focus states. The states in a
VisualStateGroup are mutually exclusive to each other.-->
<vsm:VisualStateGroup x:Name="FocusStates">
<!--Define the VisualStates in this VistualStateGroup.-->
<vsm:VisualState x:Name="Focused" />
<vsm:VisualState x:Name="Unfocused" />
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
我的定製控制需要另一個狀態,MouseButtonUp
(MouseButtonDown
可以通過預定義的Pressed
狀態表示)。這裏,默認情況下,MouseButtonUp
狀態將被解釋爲MouseOver
狀態,但我希望MouseButtonUp
狀態爲 的行爲與MouseOver
狀態的行爲不同。
如何添加這個MouseButtonUp
視覺狀態? (MouseButtonUp
只有在用戶釋放鼠標之後並且在用戶開始移動之前才存在)
順便說一句:我應該使用自定義控件還是用戶控件嗎?我一直很困惑這兩個。 。在許多情況下
非常感謝
UPDATE:一旦我們添加了這個MouseButtonUp
狀態,我能做的視覺轉換,如:
<vsm:VisualTransition From="Pressed" To="MouseButtonUp" GeneratedDuration="0:0:5" />
或者:
<vsm:VisualTransition From="MouseButtonUp" To="MouseOver" GeneratedDuration="0:0:5" />
我按照你的指示。看起來系統檢測到新狀態「MouseButtonUp」,但是我不能動畫這個狀態,例如' ',這個轉變被忽略。請指教。 –