inedi
Topic Author
Posts: 8
Joined: 06 Jan 2019, 18:16

Find XAML Resource in global Theme

20 Jun 2019, 17:38

Hello!

What can i replace WPF code
Style style = Application.Current.FindResource("key") as Style;
in Noesis / Unity ?

in code behind working:
Style style = (Style)this.FindResource("key");
but I need to find the Style in Theme.XAML from converter for my ViewModel

I will be glad to answer

Tags:
 
inedi
Topic Author
Posts: 8
Joined: 06 Jan 2019, 18:16

Re: Find XAML Resource in global Theme

21 Jun 2019, 13:04

I'm write this code:
using Noesis;
internal static class Utilities

 static FrameworkElement frameworkElement = new FrameworkElement();
 
 internal static Style GetStyle(string key)
        {
            return  (Style)frameworkElement.FindResource(key);
        }
}
using
Utilities.GetStyle("key");
And this working
This allows you to apply the style from Global XAML Theme in viewmodel, converter and etc

Why Noesis allows you to find a style not related to the new FrameworkElement - I don't know, but it works

if someone explains the mechanism, I'll be happy
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Find XAML Resource in global Theme

21 Jun 2019, 17:28

Accessing the Application.Resources is something that we should expose, I created a ticket in our bugtracker for this feature: https://www.noesisengine.com/bugs/view.php?id=1505
Why Noesis allows you to find a style not related to the new FrameworkElement - I don't know, but it works
This is working because the default behavior of FindResource in any FrameworkElement is:
  1. First search for the resource in same element Resources
  2. Next search in the same element Style.Resources
  3. Next search in the same element Template.Resources
  4. Repeat the process in the logical tree upwards until the root is reached
  5. Finally search in the Application.Resources

Who is online

Users browsing this forum: No registered users and 0 guests