Make XAML style writing more like CSS
See original GitHub issueMake XAML style writing more like CSS
- Less code
- Be more logical
- Easier to read
I don’t know if future versions have that design in mind Let’s say I want a button with rounded corners
// version now
<Window.Resources>
<Style x:Key="Btn" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border BorderThickness="1" Width="60" Height="32" CornerRadius="3" Background="#4C5EE9">
<ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="#fff"></Setter>
</Style>
</Window.Resources>
<Button Style="{StaticResource Btn}" Content="Button"></Button>
// expect version 1
<Style x:Key="Btn" TargetType="Button">
Width=60,
Height=32,
Background="#4C5EE9",
Foreground="#FFF",
BorderRadius=3
</Style>
<Button Style="{StaticResource Btn}" Content="Button"></Button>
// expect version 2
<Style>
Btn {
Width:60,
Height:32,
Background:"#4C5EE9",
Color:"#FFF",
BorderRadius: 3
}
</Style>
<Button Style="{StaticResource Btn}" Content="Button"></Button>
OR
<Button Class="{Btn}" Content="Button"></Button>
Issue Analytics
- State:
- Created 3 years ago
- Reactions:23
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Make XAML style writing more like CSS #316 - dotnet maui
Make XAML style writing more like CSS. Less code; Be more logical; Easier to read. I don't know if future versions have that...
Read more >Styling Xamarin.Forms Apps using Cascading Style Sheets ...
Xamarin.Forms supports styling visual elements using Cascading Style Sheets (CSS).
Read more >Equivalent of CSS in XAML
A resource dictionary maps pretty closely to a CSS file. Basically, you use these to store a mix of things: Styles.
Read more >Xamarin.Forms Styling with CSS
This article explores the promise of styling Xamarin.Forms apps with CSS and what lies ahead. This is a new optional way to style...
Read more >Introduction to WPF styles
WPF introduces styling, which is to XAML what CSS is to HTML. Using styles, you can group a set of properties and assign...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You’re kind of comparing apples to oranges here. Based on your “Expect version 1” your first style should look like this:
Now that’s not really that bad.
(For what it’s worth, it would be great if
<Setter Property="Width" Value="60" />
could instead be<Width>60</Width>
but I understand that XAML doesn’t work that way at all at the moment. However, I think that’s an interesting notion - could an object (like Setter) be instead replaced by a tag that isn’t itself an object but is instead just parameters? That’d be neat.)Of course, BorderRadius isn’t a property of Button. But what I suspect you’re doing is you’re trying to say “Look at all the stuff you have to do to change a template” but then what you show as “expected” does not look like it could result in a changed template.
So kind of not really comparing fairly. Again, apples to oranges.
But for sure, when you do have to create a new Template, it gets very verbose. If you wanna propose something that would make it less so, I think you would need to show something that looks like it could actually create a template.
Also, I don’t wanna exactly, you know, go all “language wars” or anything, but in my opinion: CSS is verbose. CSS is illogical. CSS is hard to read. But I’m not talking about “Color: Red” - I’m talking about when you have to write multiple nearly identical classes for lack of inheritance with -vendor-specific-tags whose values are like “split-inline-float” and you’ve got “clear: both” and !important randomly sprinkled throughout. I feel like CSS is an absolute nightmare once you move at all past the basics. So … you know, there’s that haha. I mean if you like CSS good on ya, but not everyone necessarily thinks it’s awesome.
css and html are very Bad language!Because they are not rigorous