WPF: capturing XAML into subclassed control -


I am compressing what I want my wpf button to look like using XAML

Now I would like to create a sub classified button control, which I can only use again to write that markup

   & Lt; / ControlTemplate & gt; & Lt; /Button.Template> & Lt; / Button & gt;  

How can I set all these properties using C #?

There are several ways to do this:

[Note: In this reply for the sake of , I think that you are creating a button in a simple window.]

1) Assign all the properties in a non-reusable and kind of dirty path window in a loaded event. Will happen. Giving the name of the button object, you can get it reference and provide value to the properties, register on the event and assign a template. I think you were having trouble with template properties. To create a template in the code, you can either use (which is deprecated) or use the XamlReader.Load method. (Which is a favorite approach).

2) Create a custom control for which a custom template is created in the generic.xaml file. You can retrieve their reference by overriding the name of the elements and the OnApplyTemplate method in the custom template. You can then create public assets that map the image element directly into the template or display the image element as a public property in the control. Using this approach, you can set the properties in the C # code using your highlighted properties.

3) You can also define several styles and toggle between them in the C # code. This method works like HTML when we toggle sections using javascript.

Hope it helps!


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -