Skip to content
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

Problems importing embedded styles using @import and changing the class name at runtime #102

Open
aguerrieri82 opened this issue May 4, 2020 · 1 comment
Assignees
Milestone

Comments

@aguerrieri82
Copy link

aguerrieri82 commented May 4, 2020

(I apologies for my english)
I took a look into the source, and it builds the resource name based on assembly name.

  • I can have multiple assembly with the same style name (and it's quite common in a multi-library application with some convention), and it picks up the first one matching (example)
    MyProject.Lib1
    ┖─ Style.css
    MyProject.Lib2
    ┖─ Style.css
  • The resource name in .net is built based on the default namespace rather than assembly name (90% is the same, but in my case wasn't)
    I made a little edit in GetEmbeddedResourceName, so if the source starts with #, he interprets it as full qualified resource name
  protected virtual string GetEmbeddedResourceName(string source, Assembly assembly)
        {
            if (source.StartsWith("#"))
                return source.Substring(1);
            return GetEmbeddedResourcePrefix(assembly) + source.Replace("\\", ".").Replace("/", ".");
        }

If the class name is bound and it changes during the runtime, some unpredictable behaviour occurs. I didn't have the time to full investigate the issue, but in my case was an essential feature: one of the main reason for using a css-like approch was to overcome the trigger's limitation in case of multiple condictions (es. IsMouseOver (from control) && !IsActive (from view model) and use the class to define the actual state of the view (es. "selected active default" on a list item)

P.S anyway congraturation for the huge work you made and the coding quality. I think to build an expression parser (maybe using roslyin) helping to express multiple conditions in triggers

@warappa
Copy link
Owner

warappa commented May 5, 2020

Hi @aguerrieri82 ,
first, thank you for using XamlCSS and your kind words!

I see the problem you're having. Using some form of special uri would solve this indeed.
But instead of using the #-symbol to denote embedded resources, I would prefer some sort of more standard-ish url like res://MyProject.Lib1.Style.css.
I will try to make time the next days to provide a solution to this.

PS: I'm also no native-speaker, and your english is good, no need to apologize! :)

@warappa warappa self-assigned this May 5, 2020
@warappa warappa added this to the v2.2.1 milestone May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants