Is there a way to modify a UIElement’s contents?
I have something like this:
System.IO.FileStream rdr = System.IO.File.OpenRead(xamlFilePath);
System.Windows.UIElement uie = (System.Windows.UIElement)System.Windows.Markup.XamlReader.Load(rdr);
And when I run the debugger and add uie to the “Watch” window, it gives me the following:
[-]uie
[-]System.Windows.Controls.Textbox {System.Windows.Controls.Textbox:Title}
<some stuff...>
Text "Title"
Now I need to be able to do two things: (1) read the Text in the textbox, and (2) modify it whenever I want.
I was hoping for something in the lines of:
{
Textbox tb = (Textbox)uie.GetChild();
tb.Text = "New Title"
uie.SetChild(tb);
}
, but it does not work like that. If anyone can point me to the method that performs this function I’d really appreciate it.
TextBoxis aUIElement. When you load the XAML out of the reader you could cast it to aTextBoxat that point in time; however since you are casting it to aUIElementyou could at whatever point in time go…