Why set x: name to Window.Resources elements do not work

I'm just wondering when I access most of the controls through x:Name, for the resources that I do with x:Key+, I cannot access it from the code (I could use this.Resources["keyName"])

+3
source share
2 answers

You can access resources on any FrameworkElementone as long as the element contains any resources. If it is defined in your markup, it must have x:Keyand cannot have x:Name.

If the button contains a resource, for example, you should access it from your collection Resources.

var resource = button.Resources["myKey"];

, , FindResource() .

var resource = this.FindResource("myKey");

.

+3

• x: : ResourceDictionary ( ). x: , , 90% x: , WPF.

• x: Name: , . , WPF x: Name. , , CLR , , , XAML. FrameworkElement.Name. x: Name, Name Framework WPF . .

Key for the Resources

mor on http://msdn.microsoft.com/en-us/library/ms752059.aspx

+4

Source: https://habr.com/ru/post/1763034/


All Articles