In WPF we can able to get the style based on the target type, like below:
control.Style = (Style)toplevelcontrol.TryFindResource(typeof(control))
But in WinRT I can't do that. I can only use a key to get the resource. Is it possible to get the resource based on target type? Please help me to resolve this.
Thanks in advance
The main difference between WPF and Winrt for dealing with resources here is that you get
FindResource()and siblings in WPF objects, while in Winrt you just have theResourcesproperty.The basic technique, where the object type is used as the key for
TargetTypestyles, still works though. Here's a simple helper extension method to do what you want:Call just like you would in WPF:
(Note that your original example would not compile, as
controlis a variable, and you can't usetypeofon a variable. I've fixed the bug in the above example call).