2010-10-25 72 views
0

有沒有辦法修改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到「觀察」窗口,它給了我下面的:

[-]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); 
} 

,但它不起作用。如果任何人都可以將我指向執行此功能的方法,我會非常感激。

+0

請提供您的XAML文件的內容。 – Athari 2010-10-25 20:34:06

回答

1

TextBoxUIElement。當您將XAML從讀卡器中取出時,您可以在該時刻將其轉換爲TextBox;然而,由於您正在將其轉換爲UIElement,因此您可以在任何時間點去...

if (uie is TextBox) 
{ 
    TextBox tb = (TextBox)uie; 
    b.text = "New title"; 
} 
+0

非常感謝你;有用! – SoftwareGuy 2010-10-26 18:21:59