Windows / WPF form is too big, how can I split it?

I am going to create a WPF application. So far, in uni, the only way we have ever run the GUI is to have one main window with one code file to handle button clicks, etc.

My problem is that as the application grows, the GUI grows, and the size of the code behind the file can really get out of hand!

I have identified about 15 main use cases for my system (example: enter data, details, etc.). I create a main window (size: 480x320) consisting of 15 separate screens (one for each use case). This can be achieved with a centered and stretched TabControl with 15 TabItem. Or, most likely, it could be a bunch of multilayer containers, one on top of the other (only one visible at a time).

The fact is that with 15 separate screens my code file will become huge (not to mention the xaml file!): Juggling between states - creating 14 crumbling / hidden and creating one visible, Managing controls for 15 different screens.

Is there a way to have 15 separate forms, each with its own code file, instead of 15 TabItems in one form, and then have one main engine that creates and replaces them as needed? Of course, it should look like it's one shape, not 15 pop-ups.

How can I handle this? How do you solve the problem with xaml and code-behind files with a length of thousands of lines?

+5
source share
6 answers

Your instincts are good: you do not want to put everything in one Window. You would be much better off placing each of the 15 “screens” in your own XAML file, both the user control and the page.

- , Page. StartupUri, ( ), Back Forward, Hyperlink ( NavigateUri, ) NavigationService .

"" "", "" UserControl , . , MVVM, , DataContext (, , ViewModel ), UserControl ( DataTemplate ).

MVVM, ( - - , , ). XAML . , , UserControl, , .

, MVVM, , MIX2010 " MVVM-. , MVVM, , UserControls. ( -MVVM.)

+5

WPF, MVVM commanding. IOC, , .

( ), , , . IOC, .

+6

UserControl xaml MainWindow.

, , , .. . , ! , MVC Injection Dependency .

Wpf Application Framework .

+1

From the point of view of code files, you can use #region tags so that you can collapse and expand different screens ... Although, separating it logically, this is the best approach if possible

-1
source

You can make your class partialand split it into separate files.

-2
source

All Articles