3
我想在加载的松散xaml文件中定义的文本框中设置文本。 TextBoxes是应用程序的一部分。以编程方式在加载的松散xaml中的控件上设置文本文件
StackPanel LooseRoot;
if (fTeleFound == true)
{
try
{
using (System.IO.FileStream fs = new System.IO.FileStream(sXamlFileName, System.IO.FileMode.Open))
{
LooseRoot = (StackPanel)System.Windows.Markup.XamlReader.Load(fs);
}
this.DetailsViewFrame.Children.Add(LooseRoot);
}
catch (ArgumentException ex)
{
// TBD Error xamlfile
return;
}
// set Elements
//foreach (TextBox textBox in LooseRoot.Children as TextBox) // does not work ?
//{
//
//}
}
XAML文件是这样的:
<StackPanel Margin="10" Orientation="Vertical"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Orientation="Horizontal">
<Label Margin="5,5,0,5">CRCDB=</Label>
<TextBox Margin="0,5,5,5" Name="DetailsviewTB1" Height="20"/>
<Label Margin="10,5,0,5">Infonummer=</Label>
<TextBox Margin="0,5,5,5" Name="DetailsviewTB2" Height="20"/>
<Label Margin="10,5,0,5">Daten=</Label>
<TextBox Margin="0,5,5,5" Name="DetailsviewTB3" Height="20"/>
</StackPanel>
这是一个细节的观点是要定制而不编译应用程序新。编译时不知道松散xaml文件的数量及其名称。
如何动态地设置文本框上的文本?我有一个额外的XML文件,可以指定哪些数据来自哪个文本框。
谢谢DataBinding实际上工作:) – user1550097 2012-08-03 23:55:36
@ user1550097:很高兴帮助:) – 2012-08-03 23:56:58