我想在加载的松散xaml文件中定义的TextBox中设置文本。这些TextBox是应用程序的一部分。
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 ?
//{
//
//}
}
文件如下所示:
<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文件,可以指定哪些数据出现在哪个文本框中。