Dave S.
Dave S.

Reputation: 101

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

Upvotes: 2

Views: 2732

Answers (2)

Erre Efe
Erre Efe

Reputation: 15557

You can abstract the different UI Layout Sets within different User Controls and load them according your UI logic. One way to do this is using an MVVM framework, for example, Caliburn Micro makes this a pretty simple task as doing:

ActivateItem(UILayoutViewModel);

And this call can be called from any method.

See more of Caliburn Screens and Composition at official source.

Upvotes: 2

adityaswami89
adityaswami89

Reputation: 583

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

Upvotes: 3

Related Questions