简体   繁体   中英

WPF - Access a XAML resource in code

I have a class Called Photo what i would really like to do is to create in my XAML a resource for example:

<Window.Resources>
   <local:Photo x:Key="photoKey" x:Name="myPhoto" />
</Window.Resources>

and then access it from code.

Not with FindResource() function!

I want a class member to be created just like when i create

<Button x:Name="myButton" />

Thanks for helpers!!

You can access it as Resources["photoKey"] , but not by name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM