Xaml中的数据绑定
本文关键字:数据绑定 Xaml | 更新日期: 2023-09-27 17:50:35
我无法将数据绑定到xaml…我有json,类和Xaml然后我也不能绑定数据到Xaml…我可以看到数据的后端,数据被存储到类…但无法在前端显示
这是我的json数据{
"Cities": {
"a1": "A",
"a2": "B",
"a3": "C",
"a4": "D",
"a5": "E",
"a6": "F",
"a7": "G",
"a8": "H",
"a9": "Goa",
"a10": "I"
},
"Speed": {
"Total": [
{
"name": "soso",
"cust": "88768768"
},
{
"name": "K K",
"cust": "5645654654"
},
{
"name": "Tewre",
"cust": "6werwer"
}
]
}
}
和This is my Class
public class Cities
{
public string __invalid_name__1 { get; set; }
public string __invalid_name__2 { get; set; }
public string __invalid_name__3 { get; set; }
public string __invalid_name__4 { get; set; }
public string __invalid_name__5 { get; set; }
public string __invalid_name__6 { get; set; }
public string __invalid_name__7 { get; set; }
public string __invalid_name__8 { get; set; }
public string __invalid_name__9 { get; set; }
public string __invalid_name__10 { get; set; }
}
public class Total
{
public string name { get; set; }
public string cust { get; set; }
}
public class Speed
{
public List<Total> Total { get; set; }
}
public class RootObject
{
public Cities Cities { get; set; }
public Speed Speed { get; set; }
}
and My Xaml is
<Grid>
Click="Button_Click" x:Name="getdata1"></Button>-->
<Button Content="details" Margin="48,21,0,563" Width="269" Click="getdetails"></Button>
<ListView Margin="10,114,20,0" FontSize="17" ItemsSource="{Binding Total}" Background="BlueViolet" x:Name="listviewnew" IsItemClickEnabled="True" IsEnabled="True" SelectionChanged="listviewnew_SelectionChanged" >
<ListView.Items >
</ListView.Items>
<ListView.ItemTemplate >
<DataTemplate>
<Grid>
<StackPanel Grid.Row="0" Margin="20,0,10.167,10">
<TextBlock FontStyle="Normal" Foreground="Black" x:Name="name" FontWeight="Bold" HorizontalAlignment="Stretch" FontFamily="ariel" FontSize="20" Text="{Binding name}">
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="1" Margin="20,0,0.167,0" >
<TextBlock FontSize="18" x:Name="no" FontWeight="Bold" TextWrapping="Wrap" HorizontalAlignment="Stretch" Text="{Binding cust}">
</TextBlock>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
最重要的是你的json是无效的。您不能使用城市名称作为数字。你可以检查你的json在以下链接:http://jsonlint.com/将json转换为类:http://json2csharp.com/
只需在城市名称或数字前面添加任何字符,如a1,a2,a3…