来自模态的Xaml中的数据绑定

时间:2015-05-25 10:28:36

标签: c# listview windows-phone-8 windows-phone-8.1 windows-phone-7.1

我无法将数据绑定到xaml ...我有json,class和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"
      }
    ]
  }
}

这是我的班级

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>

1 个答案:

答案 0 :(得分:0)

所有json的Forst无效.. 你不能使用城市名称作为数字.. 您可以通过以下链接查看您的json:http://jsonlint.com/ 要将json转换为类:http://json2csharp.com/

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