How to work with a large project in WPF

I am new to WPF, and I am having some problems, for example, if there are many things, how we manage them. For example, I have three borders with the same size of the same location, and they contain controls such as text fields, etc. that we build them sequentially, but when it comes to editing, we are faced with the problem of changing border located below.

So, briefly, how do we manage multiple controls on one page so that it’s easy to edit

+4
source share
2 answers

I'm not sure that I fully understand your problems, but here are a few points that make editing the WPF interface pretty easy:

  • Proper use of layout panels . If you use the absolute positioning approach for each control, this can be a nightmare for moving or resizing some controls. Proper layout (and panels like DockPanel/StackPanel/etc ) can help you a lot.
  • Inclusion of repeating parts . WPF has many features to avoid repeating user interface code. This is mainly about Styles and Control templates . If you have borders repeating throughout the window, maybe you should consider extracting that border as a ControlTemplate for ContentControl for example?
+1
source

but I found that encapsulating controls such as borders, text fields, etc. in User controls , helps keep things well-managed (not to mention code reduction), similarly using a resource dictionary to store styles / animations is useful for very large projects (remember, although local resources will take precedence when applying, so delete them, if they are not used)

In addition, using layout panels such as Stacks, grids, and docking panels allows you to collapse user controls when you don’t need it or otherwise (I also found that for some reason the grids allow overlapping controls (when the elements are ordered incorrectly in Grid Rows and Columns), which may lead to the fact that some elements will not be displayed in the design.

Plan your layout correctly and think about which panels are best for them, you need to come back much later and change can be annoying (although admittedly this happens).

Also, don't forget to use partial classes to properly structure your things, being able to read through 1000 lines of code to find something could be a nightmare.

+1
source

Source: https://habr.com/ru/post/1340472/


All Articles