Search code examples
c#wpfxaml

Multiple XAML layouts in WPF


App I am trying to create in WPF/C# has quite a few buttons in a layout with a "TV screen" type panel above (its actually an FMS emulator for commercial aircraft). Many of the buttons change the layout, which are numerous TEXTBOXs on the tv screen. My question is: is there a provision to encapsulate the layouts in different classes/files and load them into the "tv screen" at the selection of the various buttons? In other words, user hits the Flight Plan button and the layout of the 355x355 box (screen) above loads the XAML "flight_plan" layout/file/class. Each layout has different TEXTBOX sizes & locations and there are in excess of 30 different "pages", which would make encapsulating them desirable.

I am very new to WPF and c#, but have written win apps in c++ all the way back to Turbo C & OWL. I also may be trying to do something that isn't possible due to working lately in Android/Java and am confusing capabilities.

Thanks in advance.

Edit Thanks to @adityaswami89 and everyone else who got me on the right track, I have found the solution. I added the pages via a new "WPF Page" in VS2012. Then changed the "screen" to a navigation frame and it was truly simple from there. Below is the simple project I created to test it.

    public partial class MainWindow : Window
    {
       NavRad navrad = new NavRad();
       FPlan fplan = new FPlan();

       public MainWindow() {..}

       private void Frame_Navigated_1(object sender, NavigationEventArgs e) {..}

       private void Button_Click_1(object sender, RoutedEventArgs e)
       {
           Screen_Frame.Navigate(fplan);
       }

       private void Button_Click_2(object sender, RoutedEventArgs e)
       {
           Screen_Frame.Navigate(navrad);
       }

Solution

  • You can also use the concept of Frames for the intended functionality , if that can be an option you are looking.

    You can refer the below link for the same.

    http://msdn.microsoft.com/en-us/library/ms750478.aspx#Frame_in_Standalone_Applications