Skip to content

[FEAT] StyleSetter needs a better resolving mechanism #59

Description

@antokhio

Currently when apply selector I use this code:

public Style BuildStyle(StyledElement owner, Style style)
{
    if (SelectorStyle != null)
    {
        var selectorStyle = SelectorStyle.BuildStyle(owner, new Style() { Selector = Selector });

        style.Add(selectorStyle);
    }

    Input?.BuildStyle(owner, style);

    return style;
}

The problem is in SelectorStyle.BuildStyle - owner, basically when I build style like that, I match style to Control Instance i'm on, e.g. if selector applied to TextBox it would affect only properties defined by TextBox however it breaks if you apply selector to StackPanel and want to style a TextBox...

When they do that via xaml, I think it's possible like that due to markup is known in advance...

the problem is likely in:

 public static bool TryGetProperty(StyledElement owner, string propertyName, out AvaloniaProperty? property)
 {
     property = AvaloniaPropertyRegistry.Instance.GetRegistered(owner.GetType()).FirstOrDefault(p => p.Name == propertyName);
     return property != null;
 }

Witch would just bypass the property if it does not know it...
Maybe we can use something like this https://github.com/AvaloniaUI/Avalonia/blob/ad33ddbbacbf67de512892624aa8b338e30c964e/src/Avalonia.Base/LogicalTree/LogicalExtensions.cs

Not sure how to fix this, if anyone kin we might have a small chat about it....

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions