我是一名有用的助手,可以为您进行文本翻译。以下是需要翻译的内容:
我得到的错误是尝试创建Grid.Column时出错。确切的错误是{"Der unbekannte Member \"Grid.Column\" kann nicht festgelegt werden."},所以它不知道Grid.Column...有人有任何想法吗?注释掉的新XAttribute("Grid.Column", "1")这一行可以正常工作,只是不能自然地显示我想要的内容!生成的网格如下所示:
我一直在尝试创建一些动态Xaml。
我有以下c#代码:
private void LoadUI()
{
XNamespace xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
dynamic UI = new XElement(xmlns + "Grid",
new XAttribute(XNamespace.Xmlns + "x", "http://schemas.microsoft.com/winfx/2006/xaml"),
new XAttribute("Name", "Grid1"),
new XElement(xmlns + "Grid.ColumnDefinitions",
new XElement(xmlns + "ColumnDefinition", new XAttribute("Width", "100*")),
new XElement(xmlns + "ColumnDefinition", new XAttribute("Width", "200*"))),
new XElement(xmlns + "StackPanel", new XAttribute("Name", "StackLabels"),
new XAttribute("Margin", "3"),
from column in this.TableSchema
where column.IsPrimaryKey == 0 && column.DataType != "timestamp"
select
new XElement(xmlns + "Label", new XAttribute("Height", "28"),
new XAttribute("Name", column.ColumnName + "Label"),
new XAttribute("HorizontalContentAlignment", "Right"),
column.ColumnName)),
new XElement(xmlns + "StackPanel",
new XAttribute("Grid.Column", "1"),
new XAttribute("Name", "StackFields"),
new XAttribute("Margin", "3")
,
from column in this.TableSchema
where column.IsPrimaryKey == 0 && column.DataType != "timestamp"
select
GetUIElement(column)));
this.DynamicContent.Content = XamlReader.Load(UI.CreateReader());
}
我得到的错误是尝试创建Grid.Column时出错。确切的错误是{"Der unbekannte Member \"Grid.Column\" kann nicht festgelegt werden."},所以它不知道Grid.Column...有人有任何想法吗?注释掉的新XAttribute("Grid.Column", "1")这一行可以正常工作,只是不能自然地显示我想要的内容!生成的网格如下所示:
<Grid xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="Grid1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100*" />
<ColumnDefinition Width="200*" />
</Grid.ColumnDefinitions>
<StackPanel Name="StackLabels" Margin="3">
<Label Height="28" Name="NummerLabel" HorizontalContentAlignment="Right">Nummer</Label>
</StackPanel>
<StackPanel Grid.Column="1" Name="StackFields" Margin="3">
<TextBox Height="28" Name="txtNummer" Text="{Binding Path=Nummer}" />
</StackPanel>
</Grid>
XamlReader.Parse(xaml)
时会发生什么? - Emonddynamic UI = ...
替换为var UI = ...
我已经模拟了您的示例,并通过此更改使其正常工作。您确定真的需要“动态”类型吗? - SvenG