1

ChildWindowサブクラスでVisualStateManagerを使用する方法はありますか?VisualStateManagerの呼び出しは何もしません。これを実現する唯一の方法は、ストーリーボードを手動で呼び出すことです。それは非常にずさんで、エラーが発生しやすいです。誰かがそれを達成する方法を見つけましたか?

サンプルコードで更新。これを使用するには、新しいSilverlightプロジェクトを作成し、メインページのボタンクリックからExampleWindow.ShowWindow()を呼び出すだけです。コンストラクターがボタンを非表示にする状態を設定している場合でも、ボタンが表示されます。

XAML(ExampleWindow.xaml):

<controls:ChildWindow
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions"
    x:Class="Client.Windows.ExampleWindow"
    Title="Example">
    <Grid x:Name="LayoutRoot">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="ExampleStateGroup">
                <VisualState x:Name="ExampleBaseState">
                    <Storyboard>
                        <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.Opacity)">
                            <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/>
                        </DoubleAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <VisualStateManager.CustomVisualStateManager>
            <ic:ExtendedVisualStateManager/>
        </VisualStateManager.CustomVisualStateManager>
        <Button x:Name="button" Content="You Shouldn't See Me" Grid.ColumnSpan="2" Width="150" Height="150" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    </Grid>
</controls:ChildWindow>

コードビハインド(ExampleWindow.xaml.cs):

using System.Windows;
using System.Windows.Controls;

namespace Client.Windows
{
    public partial class ExampleWindow : ChildWindow
    {
        public ExampleWindow()
        {
            InitializeComponent();

            VisualStateManager.GoToState( this, "ExampleBaseState", true );
        }

        public static void ShowWindow()
        {
            var w = new ExampleWindow();
            w.Show();
        }
    }
}
4

4 に答える 4

1

この投稿をチェックするUsing Visual State Manager with Silverlight Toolkit's Child Windows control

于 2010-10-01T02:36:23.580 に答える
0

私は、VSMがChildWindowsでDovと同じように機能しないという同じ問題を経験しました。私がしたことは、ChildWindowをUserControlに変更し、UserControlを汎用のChildWindowのコンテンツとして設定してから開くことでした。

var childWindow = new ChildWindow { Content = someUserControl };

ここでの問題は、コードの動作がUserControlにあるため、ChildWindowクラスのDialogResult機能が失われることです。ChildWindowのDialogResultプロパティにアクセスする最も簡単な方法は、UserControl内でParentプロパティを使用することです。

于 2010-02-24T08:24:43.993 に答える
0

ChildWindow テンプレートには、一般的な子ウィンドウ アニメーションの VisualStateGroup "CommonStates" を管理する VisualStateManager が含まれています。VisualStateManager.GoToState を呼び出すと、ChildWindow テンプレート CommonStates VisualStateGroup で状態が検索されます。そのため、ChildWindow で作成した ExtendedVisualStateManager と VisualStateGroup "ExampleStateGroup" にアクセスする必要があります。これを行うために私が見つけた唯一の方法 (これはハックアラウンドのようなものです) は、状態変更のために呼び出される独自の GoToState 関数を作成することです。

public ExampleWindow()
{
    InitializeComponent();

    MyGoToState("ExampleBaseState");
}

public void MyGoToState(string stateIn)
{

    VisualState stateShow = null;

    VisualStateGroup ExampleStateGroup as VisualStateGroup  

    if(ExampleStateGroup != null)
    {
        for(int i= 0; i < ExampleStateGroup.States.Count; i++)
        {
            stateShow = ExampleStateGroup.States[i] as VisualState;

            if(stateShow != null)
            {

                if(stateShow.Name == stateIn.Trim())
                {
                    stateShow.Storyboard.Begin();
                }

            }

         }
    }
}
于 2014-06-22T18:26:22.093 に答える
0

これまでのところ、私が見つけた唯一の回避策は、視覚的な状態を必要とするものをすべて UserControl に入れることです。UserControl は状態を持つことができ、それらの間を正常に切り替え、イベント、メソッド、およびプロパティを通じて ChildWindow に必要なものを伝達します。

于 2010-01-25T16:29:50.873 に答える