視覚的な状態をネストすることは可能ですか? つまり、ParentControl に ChildControl があり、両方に独自の視覚状態がある場合、ParentControl の状態を設定して ChildControl の状態を適宜変更することは可能ですか。
2 に答える
1
GoToState
子コントロールの表示状態を変更するには、メソッドを呼び出す必要があります。
メソッドを呼び出す必要があるため、親コントロールの視覚状態マネージャーでストーリーボードを使用することはできません。ストーリーボードはプロパティのみをアニメーション化できるためです。
したがって、子コントロールにコードを記述する必要があります。親の状態を監視し、適切に対応するため。
これを行うにはさまざまな方法がありますが、重要な情報は、メソッドを使用して関心のある親VisualStateManager.GetVisualStateGroups
を見つけ、そのグループのイベントにアタッチすることです。したがって、子コントロール内のコードは、関心のある状態が親によって遷移されたときに通知を受けることができ、それ自体に対して適切に呼び出すことができます。VisualStateGroup
CurrentStateChanging
GoToState
于 2010-01-28T15:04:27.147 に答える
0
新しい依存関係プロパティを宣言するだけです。
public static readonly DependencyProperty StateProperty =
DependencyProperty.Register("State",
typeof( string ),
typeof( TextBlockControl ),
new PropertyMetadata("Top",
new PropertyChangedCallback(StateChanged)));
[Category("DigItOut"), Description("State")]
public string State
{
get
{
return this.GetValue(StateProperty).ToString();
}
set
{
this.SetValue(StateProperty, value);
}
}
private static void StateChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
{
if (!String.IsNullOrEmpty(args.NewValue.ToString()))
VisualStateManager.GoToState(sender as TextBlockControl, args.NewValue.ToString(), true);
}
そして、それを親の状態から設定するだけです:
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="States">
<VisualState x:Name="Reverse">
<Storyboard>
<ObjectAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="textBlockControl" Storyboard.TargetProperty="(TextBlockControl.State)">
<DiscreteObjectKeyFrame KeyTime="00:00:00">
<DiscreteObjectKeyFrame.Value>
<System:String>Bottom</System:String>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Straight"/>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
しかし、それでもトランジションの使用を制御したい場合は、別の解決策を見つける必要があります。おそらく第二物件。
于 2010-01-28T17:18:46.597 に答える