Friday, April 12, 2019

WPF: Style definition and use


WPF : Style Introduction :

Style are way to set common property of a control at one place to reuse it.
Style are similar to CSS classes in HTML/Web Applications.
We can declare Style at multiple places like :
Resource Section of Control or it's Parent.(Scope :Control it self and it's child can use this Style)
Resource Section of Window.(Scope =containing form only)
Inside of Resource Dictionary.(Scope = Application level).


Below are some common attributes of Style:

TargetType :if we are setting only TargetType then Style will be application to all controls mention as Target type in applicableScope.

x:Key : used to declare a key, if we declare a Key then style will not be applied on controls automatically, we need to set explicitly.

BasedOn : used to create a new Style by inheriting from an existing Style.

    


Note : Control level Properties have higher precedence than Style. i.e. if you have applied style which is setting background color of control and you also have set background color at Control level, Color set at control will be applicable and system will ignore color what you mentioned in Style.




No comments:

Post a Comment

C# Record type: Something to remember while using record types

  Record in c# provide a concise and expressive way to create immutable data types, record is a keyword in c#, we can use this keyword with ...