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