What is a good way to separate and simplify complex WPF user control?

I am looking for a good way to simplify and organize a complex WPF user element.

My first thought is to incorporate it into two simple controls. For an explanation I will name these SimpleControl and AdvancedControl.

SimpleControl contains all the basic functions and is extremely reusable.

AdvancedControl is dependent on SimpleControl and contains input processing and additional calls and whistles. AdvancedControl is less reusable than SimpleControl because it contains additional user interface elements and application-specific input processing.

The visual template for AdvancedControl is what defines the dependency on SimpleControl. When OnApplyTemplate is called, it caches a link to the built-in SimpleControl.

The main problem with this approach is that I want to get all the properties and methods available in SimpleControl in AdvancedControl. This means that many jobs implement the same dependency properties and methods in AdvancedControl, and then simply redirect them to SimpleControl. It does not seem particularly elegant.

I also thought about inheriting AdvancedControl from SimpleControl, but I think that in this case I would have to completely override the visual template for SimpleControl instead of reusing the existing one.

Can anyone think of a better way to decompose a complex WPF user element?

+4
source share
1 answer

You can inherit the style:

<Style TargetType="{x:Type AdvancedControl}" BasedOn="{x:Type SimpleControl}" /> 
+1
source

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


All Articles