-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A more compact Style format #480
Comments
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> |
Hi @VBAndCs, great suggestion. You introduced a Set type with this snippet:
But what if you want to create a style for another FrameworkElement, or a Control subclass? Then you need to find the properties of that other FrameworkElement or Control subclass on the Set type. That would mean there needs to be a Set type for every control type or the properties need to be dynamic somehow. This makes it complicated an I think this was a reason that led to the solution that we have today with Setters that can set any Dependency Property (That doesn't mean that there's not a better way to do it. :)) The second snippet in your first post doesn't need the Control class for the Property attributes, as you've specified it already in the TargetType. You can write it a bit shorter like this:
Then the next one with the single setter for complex types. Instead of
you can write
when Issue #84 is fixed. The fix will be a one-liner, adding the ContentPropertyAttribute to the Setter class. |
Hi @thomasclaudiushuber |
Hi @VBAndCs, ok, I understand. The idea is to extend the XAML Parser, so that it understands the Set tag as a shorthand syntax for the setters. |
@thomasclaudiushuber I had these ideas while I am working on Vazor. I use the VB XML literal to generate the Razor. I thought about using such technique with XAML somehow, or use xaml styles instead of CSS in Razor, but I found xamle style too verbose, so I thought of this. I add a middle stage between xml and razor, so, I though that this will be helpful in Xaml, especially it is dynamic and can be generated in run-time. I think we need to revise Xaml syntax and make it as shorter as possible. |
HI @VBAndCs I think posting this suggestion into this repo is good, as this is the official WPF repo. Thanks, |
Thank you @VBAndCs and @thomasclaudiushuber for the awesome discussion here! I think both https://github.com/Microsoft/microsoft-ui-xaml and here are a good place to open issues like this, quite a few of us work on both technologies so it will be seen. I personally think any improvements like this should be synchronized across UWP, WPF, and Xamarin.Forms. It's unfortunate what has happened to https://github.com/Microsoft/xaml-standard repo, although i'm hopeful that we can still align XAML dialects without necessarily creating a "XAML standard". |
It seems nobody has mentioned Xamarin.Forms CSS support. Like WPF, Xamarin.Forms has support for XAML-based styles using resource dictionaries (see e.g. here), but it adds an alternate syntax in the form of (modified) CSS. This is interesting because:
I would love to see some collaboration so that an evolved form of Xamarin.Forms's CSS can be used in WPF as well. |
Allow us to write Styles like this:
this is more compact and more readable than:
The text was updated successfully, but these errors were encountered: