c# - Setting a style on Control type not working -


I am writing a very basic WPF dialog and implementing a simple style on all the items received from the control class Want to The code I am using:

  & lt; window. Resources & gt; & Lt; Style TargetType = "{x: Type Control}" & gt; & Lt; Setter property = "margin" value = "20" /> & Lt; / Style & gt; & Lt; /Window.Resources> & Lt; StackPanel & gt; & Lt; Text block text = "some text" /> & Lt; Text box x: name = "x_NameTextBox" /> & Lt; StackPanel Orientation = "Horizontal" Horizontal Alignment = "Right" & gt; & Lt; Button x: click on the name = "x_Cancel button" = "x_Cancel Button_Link" content = "Cancel" /> & Lt; Button x: name = "x_OkButton" click = "x_OkButton_Click" content = "OK" /> & Lt; / StackPanel & gt; & Lt; / StackPanel & gt; & Lt; / Window & gt;  

The layout of the style window defined above does not change at all unless I specify a key and set the style on each individual object, which is actually what I do to avoid I am trying to It works for more specific types (for example, the button to type the target type.)

Any idea why it is not working?

Each control receives its style from the clearly defined resource when it gets instant Or searches for immediate parents where it can get a default style In your case the button will get its default style from the control panel because your app has not defined one. Now there is no way to know that platform button style is your custom defined control base style because the genre only looks for a base style when you explicitly Basedon

, you get only two modes 1. Define the style for each control - which you do not want me to think 2. Define styles for those controls Switch to the ones you set are interested and baseline to

  & gt; Style target type = "{x: type control}" & gt; & Lt; Setter property = "margin" value = "20" /> & Lt; / Style & gt; & Lt; Style TargetType = "{x: type button}" based on = "{static resource {x: type control}}" & gt; & Lt; / Style & gt;  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -