Visual Inheritance Doubt between Windows in WPF

2

I'm new to WPF and would like to clarify a question that I think most people have but can not clarify right, which is the visual inheritance of windows.

Imagine that all my registration screens should have the same appearance and the same buttons (Save, Cancel, etc.). NO Windows Forms. for example, just create a base window with the cited components and then, just make the other windows inherit from that base window and ready! If the window that inherits from the base window does not have a specific button, I just add it in the form normally.

Well, now let's go to WPF. I can not do this and I do not know if there is a possibility, because what I was able to do is to create a User Control, but I found it very stuck because if I make a user control of a screen (as I mentioned earlier), in the window that I add it , I can not change it with new buttons for that window that is inheriting ....

Has anyone had any experience like this?

    
asked by anonymous 08.11.2017 / 10:06

1 answer

0

Hello, here's an explanation from my point of view about visual inheritance and User Control Wpf.

How to create a visual inheritance wpf

It is very simple and quick to make an inheritance within wpf, select the item, choose the property to which the inherited value will be assigned, and define the parent element (which passes its value to the others) as shown in the images below through two models, model 1 displayed the percudo through graphic mode and model 2 through the code:

1.1Selecttheitemtoinheritvalues,choosetheproperty(inthebackgroundcase)andopenthepropertyoptions.

1.2ChoosetheCreatedataassociationoption.

1.3linktypeSelectElementNameiftheinheritancevalueisinaniteminyourwindoworStaticResourceifitisinastaticresourceandthenselecttheiteminlisttheleftandthepropertytoinheritfromthelistontheright.

example2-viacode

Let'ssaytheinheritance(parent)itemwillbegridPrincipalandtheheir(child)itemwillbegridMenu,thecodetoassociatethebackgroundproperty)ofgridMenugridPrincipalwouldbe:

<Gridx:Name="gridMenu" Background="{Binding Background, ElementName=gridPrincipal}"/>

There are several other processes that can be used to associate data between windows / usercontrols and etc, search and use the most suitable for your need

For more details on wpf: link

    
14.11.2017 / 18:38