0

I writing app for UWP.

I have json and write it to list.

I do it like this

 private List<RootObject> ordersList;

    public List<RootObject> OrdersList
    {
        get { return ordersList; }
        set
        {
            ordersList = value;
            OnPropertyChanged();
        }
    }


    private RootObject ordersChange;

    public RootObject OrdersChange
    {
        get { return ordersChange; }
        set
        {
            ordersChange = value;
            OnPropertyChanged();
        }
    }




    public AllOrdersViewModel()
    {
        AllOrders_down();
    }



    public async Task<string> FetchAsync(string url)
    {
        string jsonString;

        using (var httpClient = new System.Net.Http.HttpClient())
        {
            //var stream = httpClient.GetStreamAsync(url).Result;
            var stream = await httpClient.GetStreamAsync(url);

            StreamReader reader = new StreamReader(stream);
            jsonString = reader.ReadToEnd();


        }


        return jsonString;
    }


    public async void AllOrders_down()
    {


        string url = "http://api.simplegames.com.ua/inc/get_from_wc.php/?wc_orders=all_orders";


        var json = await FetchAsync(url);



        List<RootObject> rootObjectData = JsonConvert.DeserializeObject<List<RootObject>>(json);

        OrdersList = new List<RootObject>(rootObjectData);


    }

Also I have xaml where I show some of info.

Here is some of xaml code:

 <ListView x:Name="OrderList"  ItemsSource="{Binding OrdersList}"
                  SelectedItem="{Binding OrdersChange, Mode=TwoWay}" IsItemClickEnabled="True" SelectionMode="Single" ItemClick="MyClick" HorizontalAlignment="Left" Height="668" Margin="63,52,0,0" VerticalAlignment="Top" Width="350">
        <ListView.ItemTemplate>
            <DataTemplate>

                <Grid x:Name="GridInf"  RightTapped="Grid_RightTapped"   Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,1,1">
                    <TextBlock Text="{Binding date_created}"  HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap"  VerticalAlignment="Top" Width="350" Height="50" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" />
                    <TextBlock  TextAlignment="Center"  HorizontalAlignment="Left" Margin="0,146,-1,0" TextWrapping="Wrap" Text="{Binding billing.address_1}" VerticalAlignment="Top" Height="58" Width="350" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" />
                    <TextBlock  HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="{Binding billing.first_name}" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" Padding="0,0,0,0"/>
                </Grid>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

In this row <TextBlock Text="{Binding date_created}" HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Width="350" Height="50" FontFamily="SF UI Display" FontSize="25" FontWeight="Light" Foreground="White" /> I need to show something like number of value in list + {Binding date_created}.

So for first it will be 1+ {Binding date_created} etc.

How I can do this?

Thank's for help

Eugene
  • 231
  • 2
  • 13
  • So the orders don't have a number from themselves? Does it have to be in one TextBlock? Can you introduce an OrderViewModel? – H H Dec 12 '16 at 12:32
  • Yes, it don't have. If it possible it may be in one TextBlock @HenkHolterman – Eugene Dec 12 '16 at 12:49
  • 1
    Possible duplicate of [Getting index of an item in an ObservableCollection inside the item](http://stackoverflow.com/questions/31436817/getting-index-of-an-item-in-an-observablecollection-inside-the-item) – AVK Dec 12 '16 at 15:30

0 Answers0