Doubt about Visual Inheritance between Windows in WPF

Asked

Viewed 196 times

2

I’m new to WPF and I’d like to clear up a question that I think most people have, but can’t quite clear up, which is the visual heritage of windows.

Imagine that all my sign-up screens should look the same and have the same buttons (Save, Cancel, etc). IN Windows Forms. for example, just create a base window with the above components and then just make the other windows inherit from this base window and that’s it!! If the window you inherit from the base window doesn’t have a specific button, I just add it to the form normally.

Well, now we go to the WPF. I can’t do this and I don’t know if there is such a possibility, because what I was able to do is create a User Control, but I found it very plastered because if I do a user control of a screen (as I mentioned earlier), in the window I add it, I can’t change itlo with new buttons for that window you’re inheriting....

Has anyone ever been through such an experience?

  • I know that inheritance has even to use, but it’s complicated, I think it’s not worth it. I tried to mess with it once, and I didn’t go into it. I will wait for an answer how to do to reuse the visual between the windows =]

1 answer

0


Hello, here’s an explanation of my view on visual heritage and Wpf User Control.

How to create a wpf Visual Heritage

It is very simple and fast to make an inheritance within wpf, select the item, choose the property to which you will receive the inherited value and set the parent element (which passes its value to others) as displayed in the images below through two templates, the model 1 display the percussion via graphic mode and the model 2 through the code:

1.1

1.1 Select the item to inherit the values, choose the property(in the background case) and open the property options.

1.2

1.2 Choose the option Create Data Association.

1.3

1.3 in type of binding select Elementname if the inheritance value is in an item in your window or Staticresource if you are in a static resource and then select the item in the list on the left and the property to be inherited in the list on the right.

example 2 - via code

let’s say that the item of inheritance(father) will be the gridPrincipal and the item heir(son) will be the gridMenu, the code to associate the background(or any other property) of gridMenu the gridPrincipal would be:

<Grid x: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 about wpf data association: https://msdn.microsoft.com/pt-br/library/ms750612(v=vs.110). aspx

Browser other questions tagged

You are not signed in. Login or sign up in order to post.