Skip to content

Proper Way to Retrieve FA Resources in Code-Behind #378

Answered by amwx
robloo asked this question in Q&A
Discussion options

You must be logged in to vote

We have two "universal" resource look up methods, implemented as extension methods:
void IResourceHost.FindResource(ThemeVariant variant, object key)
bool IResourceHost.TryFindResource(object key, ThemeVariant variant, out object value)

Both of these will walk the tree up from the control to the App. FindResource will return UnsetValue if the resource isn't found and TryFindResource returns a bool to determine lookup success.

Unlike WPF/UWP, we have two places resources can be defined, Styles and Resources. When doing a lookup, you have to remember to search both, Resources first, then Styles. So instead of special casing FATheme, just loop over the Styles collection in App and call TryGe…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@robloo
Comment options

Answer selected by robloo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants