0

I've a ContentControl which binds it Content to a variable

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

The ContentControl is in my view 'MainPage.xaml' When I click on a Button, the Content of my ContentControl is set to a new View, i.e. 'FirstPage.xaml'. So I have MainPage.xaml, which includes a ContentControl with the Content 'FirstPage.xaml'.

The problem is that I've set a VisualStateManager in my MainPage.xaml and in my FirstPage.xaml.

If I test the VisualState 'Snapped' for both in Xaml-Editor, it works fine. Problem -> MainPage.xaml includes ContentControl = FirstPage.xaml. If MainPage.xaml is Snapped, only the VisualState of MainPage is being applied, but the ContentControl will still be the same (Not VisualState Changing in ContentControl).

So how do I apply the VisualState in a ContentControl?

bash.d
  • 13,029
  • 3
  • 29
  • 42
Rudi
  • 926
  • 2
  • 19
  • 38

1 Answers1

0

Problem solved. I have to put this in the code-behind:

    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);
    }
Rudi
  • 926
  • 2
  • 19
  • 38