WPF - VisualStateManager - Как мне? - PullRequest
1 голос
/ 05 марта 2010

В моей VisualStateManagerGroup есть два состояния: "VisualStateLogin".
Как перейти из базового состояния в другое при загрузке моего окна?

Я пробовал:

public MainWindow()
{
    this.InitializeComponent();

     //Initializes the mainwindow in a user loogedoff state

     this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}

void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
     VisualStateManager.GoToState(this, "LoggedOff", true);
}

Это мой код XAML:

    <VisualStateManager.CustomVisualStateManager>
        <ic:ExtendedVisualStateManager/>
    </VisualStateManager.CustomVisualStateManager>
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="VisualStateLogin">
            <VisualStateGroup.Transitions>
                <VisualTransition GeneratedDuration="00:00:00.6000000"/>
            </VisualStateGroup.Transitions>
            <VisualState x:Name="LoggedOn"/>
            <VisualState x:Name="LoggedOff">
                <Storyboard>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="brdContent" Storyboard.TargetProperty="(UIElement.Opacity)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.1"/>
                    </DoubleAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="brdTab" Storyboard.TargetProperty="(UIElement.Opacity)">
                        <SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.4"/>
                    </DoubleAnimationUsingKeyFrames>
                    <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="brdContent" Storyboard.TargetProperty="(UIElement.IsHitTestVisible)">
                        <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True"/>
                    </BooleanAnimationUsingKeyFrames>
                    <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="brdTab" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                        <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False"/>
                    </BooleanAnimationUsingKeyFrames>
                    <BooleanAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="brdContent" Storyboard.TargetProperty="(UIElement.IsEnabled)">
                        <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="False"/>
                    </BooleanAnimationUsingKeyFrames>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>

Спасибо

Ответы [ 2 ]

1 голос
/ 09 апреля 2013

Первое: Хосимарис Мартареллис ответил хорошо.

Но если у вас есть выбор, я предпочитаю генерировать собственный UserControl в качестве единственного корня окна и выполнять VisualStates для этого UserControl. Таким образом, вам не нужно полагаться на ExtendedVisualStateManager и не нужно добавлять дополнительные библиотеки DLL в проект (для решения «ExtendedVisualStateManager.GoToElementState» необходимо добавить «microsoft.expression.interactions.dll»)

1 голос
/ 07 марта 2010

Я должен решить это так:

    public MainWindow()
    {
        this.InitializeComponent();

        //Initializes the mainwindow in a user loogedoff state

        this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
    }

    void MainWindow_Loaded(object sender, RoutedEventArgs e)
    {
        ExtendedVisualStateManager.GoToElementState(this.LayoutRoot as FrameworkElement, "LoggedOff", false);        
    }

http://jack.ukleja.com/workaround-for-visualstatemanager-gotostate-not-working-on-window/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...