我正在讨论这个问题,但我在最后一行收到错误
string dt = @“
<TextBlock
Text=""{Binding Codigo}""
FontSize=""{StaticResource PhoneFontSizeNormal}""
Grid.Column=""0""
VerticalAlignment=""Top""/>
<TextBlock
Text=""{Binding Nombre}""
FontSize=""{StaticResource PhoneFontSizeLarge}""
Grid.Column=""1""
VerticalAlignment=""Top""/>";
listLineas.ItemTemplate = (DataTemplate)XamlReader.Load(dt);
由于
答案 0 :(得分:2)
不应该在字符串中创建有效的XAML DataTemplate吗?
string dt = @"
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<StackPanel>
<TextBlock
Text=""{Binding Codigo}""
FontSize=""{StaticResource PhoneFontSizeNormal}""
Grid.Column=""0""
VerticalAlignment=""Top""/>
<TextBlock
Text=""{Binding Nombre}""
FontSize=""{StaticResource PhoneFontSizeLarge}""
Grid.Column=""1""
VerticalAlignment=""Top""/>
</StackPanel>
</DataTemplate>";
listLineas.ItemTemplate = (DataTemplate)XamlReader.Load(dt);
请注意,必须声明一个默认的命名空间,并且内容只能设置一次(因此包装StackPanel)