我正在创建一个 Windows 应用商店应用程序。我想创建一个类似结构的表,所以我使用了 ItemsControl。我需要在给定的 JSON 下方显示,它是表中字符串列表的列表。我从这里尝试了一些东西,但我得到了重复的输出。
JSON
{
head:[
[
"Your purchase",
"Short number",
"SMS text",
"Price",
"Operator"
]
],
body:[
[
"10",
"28000",
"PAY 2p+2508812",
"23.20 MXN",
"TELCEL"
],
[
"10",
"28000",
"PAY 2p+2508812",
"23.20 MXN",
"MOVISTAR"
],
[
"6",
"53035",
"dam 10169 2508812",
"15.08 MXN",
"IUSACELL"
],
[
"10",
"28000",
"PAY 2p+2508812",
"23.20 MXN",
"Nextel"
],
[
"10",
"28000",
"PAY 2p+2508812",
"23.20 MXN",
"Lusacell"
]
]
}
模型类
public class SmsTable
{
[JsonProperty("head")]
public List<List<string>> Headers { get; set; }
[JsonProperty("body")]
public List<List<string>> RowValues { get; set; }
}
XAML
<ItemsControl x:Name="icOuter" Grid.Row="1" ItemsSource="{Binding RowValues}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl x:Name="icInner" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Left">
<StackPanel Orientation="Horizontal" Background="White" HorizontalAlignment="Left">
<Border Style="{StaticResource BorderCell}">
<TextBlock Text="{Binding Items[0], ElementName=icInner}" Style="{StaticResource TextBlockCell}" Width="180"/>
</Border>
<Border Style="{StaticResource BorderCell}">
<TextBlock Text="{Binding Items[1], ElementName=icInner}" Style="{StaticResource TextBlockCell}" Width="180"/>
</Border>
<Border Style="{StaticResource BorderCell}">
<TextBlock Text="{Binding Items[2], ElementName=icInner}" Style="{StaticResource TextBlockCell}" Width="245"/>
</Border>
<Border Style="{StaticResource BorderCell}">
<TextBlock Text="{Binding Items[3], ElementName=icInner}" Style="{StaticResource TextBlockCell}" Width="125"/>
</Border>
<Border Style="{StaticResource BorderCell}">
<TextBlock Text="{Binding Items[4], ElementName=icInner}" Style="{StaticResource TextBlockCell}" Width="125"/>
</Border>
</StackPanel>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
预期产出
实际输出