模态 Xaml 中的数据绑定

Data Binding in Xaml from modal

我无法将数据绑定到 xaml...我有 json、class 和 Xaml 然后我也无法绑定数据到 xaml...我可以看到数据正在存储到 Class 的后端...但无法在前端显示

这是我的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"
      }
    ]
  }
}

这是我的 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; }
}

我的 Xaml 是

 <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 全部无效.. 你不能使用城市名称作为数字.. 您可以在以下 link 中检查您的 json:http://jsonlint.com/ 将 json 转换为 class :http://json2csharp.com/

只需在城市名称或数字前添加任何字符,如 a1、a2、a3...