Search code examples
c#listviewwindows-phone-8windows-phone-8.1windows-phone-7.1

Data Binding in Xaml from modal


I am not able to bind data to xaml... i have json, class and Xaml then also i am not able to bind the data to the xaml...i can see data the backend that data is getting stored into the Class...but is unable to show at the front End

This is my json data

{
  "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"
      }
    ]
  }
}

and 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>

Solution

  • Forst of all your json is invalid.. You can not use City name as Digit.. You can check your json in following link: http://jsonlint.com/ To convert json to class : http://json2csharp.com/

    Just add any character before the cityname or Digit like a1,a2,a3...