Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

A more compact Style format #235

@VBAndCs

Description

@VBAndCs

Allow us to write Styles like this:

<Style Key="Style1" TargetType="Control">
   <Set
    Foreground = "#66603a"
    Background = "#fff4e4"
    BorderBrush = "Red"
    BorderThickness = ".5,.5,1.5,1.5"          
    FontFamily = "Times New Roman" 
    FontSize= "18" 
    FontWeight = "Bold" 
    FontStyle = "Oblique"
    Padding = "5" 
    Margin = "10" />

    <Handle MouseEnter ="Control_MouseEnter"/>
</Style>

this is more compact and more readable than:

<Style Key="Style1" TargetType="Control">
      <Setter Property="Control.Foreground" Value="#66603a" />
      <Setter Property="Control.Background" Value="#fff4e4"/>
      <Setter Property="Control.BorderBrush" Value="Red"/>
      <Setter Property="Control.BorderThickness" Value=".5,.5,1.5,1.5"/>          
      <Setter Property="Control.FontFamily" Value="Times New Roman" />
      <Setter Property="Control.FontSize" Value="18" />
      <Setter Property="Control.FontWeight" Value="Bold" />
      <Setter Property="Control.FontStyle" Value="Oblique"/>
      <Setter Property="Control.Padding" Value="5" />
      <Setter Property="Control.Margin" Value="10" />

    <EventSetter Event="MouseEnter"  Handler="Control_MouseEnter"/>
</Style>

For complex value, there is a little to enhance:

<Style>
        <Set BorderBrush="new()">
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="Yellow" Offset="0.0" />
                    <GradientStop Color="Red" Offset="0.25" />
                    <GradientStop Color="Blue" Offset="0.75" />
                    <GradientStop Color="LimeGreen" Offset="1.0" />
                </LinearGradientBrush>
        </Set>
</Style>

instead of

<Style>
        <Setter Property="BorderBrush" >
            <Setter.Value>
                <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                    <GradientStop Color="Yellow" Offset="0.0" />
                    <GradientStop Color="Red" Offset="0.25" />
                    <GradientStop Color="Blue" Offset="0.75" />
                    <GradientStop Color="LimeGreen" Offset="1.0" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
</Style>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions