列表

时间:2016-12-12 10:38:18

标签: c# visual-studio xaml uwp

我为UWP撰写应用程序。

我有json并将其写入列表。

我这样做

 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);


    }

此外,我还有xaml,其中显示了一些信息。

以下是一些xaml代码:

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

在这一行<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" />中,我需要在list + {Binding date_created}中显示类似值的内容。

首先,它将是1 + {Binding date_created}等。

我怎么能这样做?

感谢帮助

0 个答案:

没有答案