2013-04-17 46 views
0

我結合它的內容給一個變量ContentControl中VisualStateManager

<ContentControl x:Name="MyContentControl" Content="{Binding MyContent}" /> 

的ContentControl中在我看來是一個ContentControl中「MainPage.xaml中」 當我點擊一個按鈕,我ContentControl中的內容設置到一個新的視圖,即'FirstPage.xaml'。 所以我有MainPage.xaml,其中包含ContentControl與內容'FirstPage.xaml'。

問題是我在MainPage.xaml和FirstPage.xaml中設置了VisualStateManager。

如果我在Xaml-Editor中測試VisualState'Snapped',它工作正常。問題 - > MainPage.xaml包含ContentControl = FirstPage.xaml。如果MainPage.xaml是Snapped,則只應用MainPage的VisualState,但ContentControl仍然是相同的(不是VisualState在ContentControl中更改)。

那麼如何在ContentControl中應用VisualState?

回答

0

問題已解決。我必須把它放在代碼隱藏的地方:

public MainPage() 
    { 
     this.InitializeComponent(); 
     Window.Current.SizeChanged += Current_SizeChanged; 
    } 

    void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e) 
    { 
     VisualStateManager.GoToState(this, ApplicationView.Value.ToString(), true); 
    }