2010-03-04 2 views
1

У меня есть два состояния внутри моей VisualStateManagerGroup: «VisualStateLogin».
Как перейти от базового состояния к другому, когда мое окно загружено?WPF - VisualStateManager - Как мне?

Я Пытался его:

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> 

Спасибо

+0

Вы , за шанс, используя Blend? – Jay

+0

да, я использую Blend. –

ответ

1

Я должен решить это следующим образом:

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/

1

Первый: Josimaris Martarellis ответ в порядке.

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

Смежные вопросы