visual studio 2008 - How do I properly style a button in WPF? -


I know that this is a basic question, but I am having trouble understanding how to do it properly.

Looking at the following XAML:

  & lt; Button & gt; & Lt; Grid grid. Raw = "1" & gt; & Lt; Grid.ColumnDefinitions & gt; & Lt; Column width = "16" /> & Lt; Column width = "*" /> & Lt; /Grid.ColumnDefinitions> & Lt; Image grid. Column = "0" width = "16" height = "16" source = "resource / accept" /> & lt; TextBlock Grid.Column = "1" margin = "2" & gt; Continue & lt; / TextBlock & gt; & Lt; / Grid & gt; & Lt; / Button & gt;  

How do I change it to a style so that it can be easily reused? What if I want to supply an image source and text in a feature? Is this possible?

On the related note, what are the best practices for structuring files, where do you store your own styles and more? Do you just leave them in a new XML file and paste them into the Solutions folder?

I am very new in WPF, therefore, again, I apologize for the original question.

Ian

edit 1:

There are a few ways of style controls, you can access them as StaticResource , or you can provide a TargetType , so that's why all genres Can be implemented under the control of.

You can consider databanking to parameter your style, for example if you have a model that supplies content for these buttons, then you can do something like this:

  & lt; Grid.Resources & gt; & Lt; Style TargetType = "Button" & gt; & Lt; Setter Property = "Content" & gt; & Lt; Setter.Value & gt; & Lt; Grid & gt; & Lt; Grid.ColumnDefinitions & gt; & Lt; Column width = "16" /> & Lt; Column width = "*" /> & Lt; /Grid.ColumnDefinitions> & Lt; Image grid. Column = "0" width = "16" height = "16" source = "{binding path = image}" /> & Lt; Text block grid Column = "1" margin = "2" text = "{binding path = text}" /> & Lt; / Grid & gt; & Lt; /Setter.Value> & Lt; / Setter & gt; & Lt; / Style & gt; & Lt; /Grid.Resources> & Lt; Button x: name = "myButton1" width = "100" height = "100" />  

This would be an example of setting up content.

  myButton1.DataContext = new button caption {text = "test"}; Public class button Captain {public image image {get; Set; } Public string text {get; Set; }}  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -