vendredi 1 mai 2015

How can I access XAML controls via reflection?

I have a base class, "PBase" that extends from UserControl and has a handful of XAML descendants, e.g., "PStopwatch" and "PReadOnly".

PBase itself does not have any .XAML associated with it, but both "PStopwatch" and "PReadOnly" do, and both have defined a field label in their .XAML likeso:

 <Controls:FieldLabel x:Name="lblPrompt" DockPanel.Dock="Left">Label</Controls:FieldLabel>

I am trying to change the value of this label dynamically, at runtime. I am reasonably certain that I can do this via reflection, but I have run into two issues.

Firstly, is the "lblPrompt" control above considered a property, a field, or something else?

Secondly, the value I wish to change is "lblPrompt.Text", so do I have to (essentially) do the reflection twice? (Once for lblPrompt and then on the result of that for Text?)





Aucun commentaire:

Enregistrer un commentaire