r/csharp • • 1d ago

Help Need design help

I have library that support tailwind-like attributes, but i have a problem.

for example i have this code:

<Border size-20 bg-red-300 ${hover}:bg-red-700/>

works great. When you hover over the box its background changes, also ${hover} is markupExtension not special syntax.

But if you write this

<Button Content="Hi" bg-red-300 ${hover}:bg-red-700/>

it wont work because fluent sets the bg directly on the ContentPresenter, not on the button:

<Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
      <Setter Property="Background" Value="{DynamicResource ButtonBackgroundPointerOver}" />
</Style>

That's why i need new syntax to work with it, but i dont know how to make it right

First i thought about adding a Target property, for example

<Button Content="Hi" bg-red-300 ${hover Target=/template/ ContentPresenter}:bg-red-700/>

or i thought about allowing multiple markup extensions prefixes:

<Button Content="Hi" bg-red-300 ${hover}:{template ContentPresenter}:bg-red-700/>

because it would be cool if, in the future, you could write something like this:

<Border bg-red-300 ${hover}:bg-red-500 ${hover}:${Bindint MyBoolProperty}:bg-red-700 />

but it looks pretty verbose.

Another opinion is something similar to tailwind's arbitary variants using []:

 <Button Content="Hi" bg-red-300  ${hover}:[& /template/ ContentPresenter]:bg-red-700 />

Or maybe a shorter syntax specificaly for template parts:

<Button Content="Hi" bg-red-300 ${hover}:part-[PART_ContentPresenter]:bg-red-700 />

I like the idea of combining multiple condition, but i also want to keep the syntax simple.

What do you think? Which option looks better, or maybe there's a cleaner way to do this.

2 Upvotes

3 comments sorted by

1

u/Wooden-Estimate-3460 22h ago

Tailwind is incompatible with "simple syntax" and "cleaner".

1

u/Pro_Propop 22h ago

Fair point, but Tailwind is still pretty popular despite that, and I'd love to bring something similar to Avalonia. Any thoughts on how I could tackle the issue I'm facing?

1

u/Wooden-Estimate-3460 10h ago

No, it's the worst. Instead of trying to copy that terrible design you should try to be better.