Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

StyleKeyOverride should have a defaut value to parent control type

Open dbriard opened this issue 1 year ago • 5 comments

An example more than hundred words.

I am create a control that heritate from another control (i.e. ContentControl) and I don't plan to modify the style, I just want to add properties or tweak somethings.

without protected override Type StyleKeyOverride => typeof(ContentControl); the new control is not displayed in the UI.

Don't you think it would be more useful to use the parent control theme by default, instead of nothing? when no theme is provided/required.

dbriard avatar Jul 05 '23 10:07 dbriard

That's a really good question. We have no real idea how to handle this. There are several ideas:

  • provide a minimal control template
  • use parent
  • throw an exception?
  • throw a warning?

The biggest issue is, you will have to maintain it and there will be edge-cases where this is not whished or even harmful. So it's probably not easy as one thinks in the first step.

timunie avatar Jul 05 '23 12:07 timunie

Today our customer encountered an opposite issue😂. Window on the other hand has a fixed stylekey, which means any inheritance will use Window as stylekey by default. His custom template will never be applied until explicitly setting stylekey to itself which is a really weird behaviour.

rabbitism avatar Jul 05 '23 12:07 rabbitism

okay, interesting. Still a message or any kind of exception would be useful. "No Style found, fix it / import it". We have this kind of question often for DataGrid for example.

timunie avatar Jul 05 '23 13:07 timunie

I think it's enough to add an analyzer that signals the problem.

workgroupengineering avatar Jul 05 '23 13:07 workgroupengineering

In fact, as I am working on Avalonia since 11 preview 4, I read all the iterations of the API and so I read about the new StyleKeyOverride API (and I got errors upgrading to RC2), so I do not spend too much time to found the issue.

But I think that new customers may spend more time to understand why a simple inherited control is not visible. As far as I remember, in WPF, inherited control are using the parent style by default (I think?).

I often heritate from ContentControl (or any other control) because I want a typed ContentControl to add a few properties, but I still want it behave like a ContentControl by default if I do not provide a custom Theme.

Is there any use case for an invisible control without a Theme?

I get the same issue the first time I used HeaderedContentControl which do not come with a default theme and was invisible in my views.

I get into Avalonia for 4 months so I start to forgot about UWP or WPF :D, but I think that the parent style is use by default if no style is found.

Today, I copy pasted a class from a UWP sample and it do not work if I do not set StyleKeyOverride.

At least a visible warning, or some kind of problem detection in analyzer would be useful :)

dbriard avatar Jul 05 '23 14:07 dbriard