简体   繁体   中英

WPF best way for changing layout dynamically

i'm starting to build a C# WPF application, and i want to have a control with multiple "screens" (actually - another UserControl s), but i want to let the user choose between several layout presets.
for example - split that main control into 4/9/16/64 windows, or to have one big window in the middle and small ones at the edges.
so i know how to build the layout of each "mode", but how should i switch between them?
after all, i want to have one main control with a method like:

mainControl.SwitchMode(Modes.LAYOUT_4_SCREENS);

and the control will change the layout in an elegant way (code-speaking), and place each screen (another UserControl ) in the right place.
any suggestions?

You could probably programatically change the content of a wrapping Grid. and in the different grids you could build your Layouts. But I think a more developer-friendly approach would be to simply create different views (usercontrols) and then switch the content of a wrapping grid to the different usercontrols ie

<Grid x:Name="LayoutRoot">
</Grid>

codebehind:

Layout4ScreenView screenView4 = new Layout4ScreenView();
Layout2ScreenView screenView2 = new Layout4ScreenView();

Switch(LayOut)
{
case Mode.LAYOUT_4_SCREENS:
LayoutRoot.Content = screenView4;
break;

case Mode.LAYOUT_2_SCREENS:
LayoutRoot.Content = screenView2;
break;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM