如何修改 UIElement 的内容?
有没有办法修改 UIElement 的内容?
我有这样的事情:
System.IO.FileStream rdr = System.IO.File.OpenRead(xamlFilePath);
System.Windows.UIElement uie = (System.Windows.UIElement)System.Windows.Markup.XamlReader.Load(rdr);
当我运行调试器并将 uie 添加到“Watch”窗口时,它会给出以下内容:
[-]uie
[-]System.Windows.Controls.Textbox {System.Windows.Controls.Textbox:Title}
<some stuff...>
Text "Title"
现在我需要能够做两件事:(1)读取文本框中的文本,并且(2) 随时修改。
I was hoping for something in the lines of:
{
Textbox tb = (Textbox)uie.GetChild();
tb.Text = "New Title"
uie.SetChild(tb);
}
,但它不是那样工作的。如果有人能指出执行此功能的方法,我将非常感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TextBox
是一个UIElement
。当您从阅读器中加载 XAML 时,您可以及时将其转换为TextBox
;然而,由于您将其转换为UIElement
您可以在任何时间点去...TextBox
is aUIElement
. When you load the XAML out of the reader you could cast it to aTextBox
at that point in time; however since you are casting it to aUIElement
you could at whatever point in time go...