c# - Accessing a resource via codebehind in WPF -


My custom resources are defined in my window resources (in a sketchflow app so that the window is actually a user tran Ho):

   & Lt; /UserControl.Resources>   

I want to be able to refer to this collection in the codebehind, which I hope that X: name will be, but I can not access it.

I can get a reference using this

  myRef = (MyCollection). FindName ("myKey");  

But it seems hacks. Is this bad practice, and what would be better? Thank you :)

You use the System.Windows.Controls.UserControl Should s FindResource () or TryFindResource () methods.

In addition to this, a good practice is to make a string constant which is the name of your key resource dictionary (so that you can change it only in one place).


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -