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

A more compact Style format #235

Open
VBAndCs opened this issue Mar 31, 2019 · 1 comment
Open

A more compact Style format #235

VBAndCs opened this issue Mar 31, 2019 · 1 comment

Comments

@VBAndCs
Copy link

VBAndCs commented Mar 31, 2019

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>
@VBAndCs
Copy link
Author

VBAndCs commented Apr 2, 2019

Note:
There is no need to create a Set type.
Parse <Set /> as an xml tag and get its Attr / Value pairs, then create a XAML Setter for each pair, and them to the Style. This can happen in run-time or in the precompiled BAML. This is a straight forward easy solution.
The only work to do, is make the editor / Xaml parser check that each attr written in the Set tag is a property in the TargetType with a valid value, of course with intellisense support.
This should be easier in the absence of the TargetType , where each attr (property) is fully qualified (i.e Control.Foreground = ...).
My aim here is to have a 2-stage Xaml parsing, to allow using some shortcut syntax, that expanded in run-time to the formal Xaml syntax.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant