WpfAppStyles1( WPF )

Objectives:
  • Styles are Cascading Style Sheet (CSS) of WPF
    • Name Style with Property and Static enforcement
    •  <Window.Resources>
      <Style x:Key="anyName">
  • Styles :
    • Named Styles
    • Event Setter
  • Code : MainWindow.xaml.txt, MainWindow.xaml.cs.txt

Style Class

Properties Description
Setters  Provides six options to pick , ClipBoard, CollectionViewSource, PresentationTraceSources, Property,TargetName, Value, x:, {} xml, xmlns

Uses: to enforce uniform style to the controls .

Resources  Under Resources, Style can set either Key or Name as reference point; else when used stand alone <Style > XAML node will have only "Name" attribute as a reference point. 
Style BasedOn Each style can support only one BasedOn value like "{ StaticResource Style1 "}
Triggers As the name suggests, triggers will allow the changes in the style like foreground, with the onset of an event.
Target Type Allows to impose a property to an element like TextBlock
Step:1 Create a New project

Add Two Button and One Text Box (Please refer XAML Mark up ) .

Step:2 Short discussions on Styles XAML mark up :

a) Named Styles : In the named style, XAML mark allows to set common properties, which can be used used by the controls

  • Setter requires two attributes, namely, "Property" and "Value" respectively. 
    • The Property attributes in the Named styles need to include Class Name

In Named Styles, you Can's use regular event implicitly; If we had integrated an event, as a matter of  argument, then A Label or TextBox control could inherit/import a Click event; and normally these controls are not supped to be using Click events. Thereby, Named style would have ignored general rules created under WPF, Windows framework. 

b) Targeted Styles can use the assigned events of the Specific control , along with Setter properties.

The Mark up script of the controls used in this application.

Step:3 Edit MainWindow.xaml.cs

Step:4

Runtime View

a) Testing "Control.BackGround"

All the controls inherited Beige background.

b) Testing Button, "B1" event. It did not trigger any event,  as anticipated

c) Activate B1's "Click" event via other  events.

Message box intercepted the changes.

Then the Button's backgrounds changed as anticipated.

Now B1, showing Code prevails, would bind to a Click event, as shown below

c) Text changed

Entering text will change, button B1's background property, but won't acquire any event;     as shown below.