3

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!!

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

2 Comments

no way a class member can be created from this XAML code? and why is it? what is the difference between creating it in the Resources or just in XAML code under a grid for example?
You can assign Resources["xx"] to a variable in constructor and use that. x:Key is the only identifier for a resource, x:Name is ignored.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.