2010-03-04 5 views
1

J'ai deux états dans VisualStateManagerGroup: "VisualStateLogin".
Comment passer de l'état de base à un autre lorsque mon Window est chargé?WPF - VisualStateManager - Comment faire?

Je l'ai essayé:

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); 
} 

Ceci est mon code 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> 

Merci

+0

Êtes-vous , par hasard, en utilisant Blend? – Jay

+0

oui, j'utilise Blend. –

Répondre

1

je suis arrivé à le résoudre de cette façon:

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

D'abord: Josimaris Martarellis réponse est ok.

Mais si vous avez le choix, je préfère générer un UserControl propre comme la seule racine de la fenêtre et exécuter VisualStates sur ce UserControl. Vous n'avez donc pas besoin de compter sur ExtendedVisualStateManager et n'avez pas à ajouter de DLL supplémentaires à votre projet (vous devez ajouter "microsoft.expression.interactions.dll" pour la solution "ExtendedVisualStateManager.GoToElementState")

Questions connexes