值不在 Windows 应用商店应用中的预期范围内
本文关键字:应用 范围内 Windows | 更新日期: 2024-11-07 18:51:22
我的xaml编码是这样的:
<Page
x:Name="pageRoot"
x:Class="wCommander.OrderListing"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:wCommander"
xmlns:common="using:wCommander.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"><Page.Resources>
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
<x:String x:Key="AppName">Order Lists</x:String>
<Style x:Key="ContactGroups" TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</Page.Resources>
<!--
This grid acts as a root panel for the page that defines two rows:
* Row 0 contains the back button and page title
* Row 1 contains the rest of the page layout
-->
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Back button and page title -->
<Grid Grid.Row="0" Background="#009DC6">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="120"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button x:Name="backButton" Margin="39,30,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
Style="{StaticResource NavigationBackButtonNormalStyle}"
VerticalAlignment="Top"
AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button"/>
<TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1"
IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Center" Margin="0,0,30,15" FontSize="36"/>
</Grid>
<Grid Grid.Row="1" Background="#FFFFFF">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="ORDER ID" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Grid.Column="0" Foreground="#FF58B3D2"/>
<TextBlock Text="CUSTOMER NAME" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="20" Grid.Column="1" Foreground="#FF58B3D2"/>
<TextBlock Text="ORDER DATE" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Grid.Column="2" Foreground="#FF58B3D2"/>
<TextBlock Text="ORDER TOTAL" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Grid.Column="3" Foreground="#FF58B3D2"/>
<TextBlock Text="STATUS" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Grid.Column="4" Foreground="#FF58B3D2"/>
<TextBlock Text="ACTIONS" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Grid.Column="5" Foreground="#FF58B3D2"/>
</Grid>
<ListView x:Name="OrderListView" HorizontalAlignment="Stretch" ItemContainerStyle="{StaticResource ContactGroups}" VerticalAlignment="Stretch" Background="#FFFFFF" Margin="0,0,0,0" Grid.Row="2" SelectionMode="Single" SelectionChanged="index_selected" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding id}" Height="auto" Width="auto" Margin="25,0,25,0" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="#636D6F" Grid.Column="0"/>
<TextBlock Text="{Binding customerName}" Height="auto" Width="auto" Margin="0,0,0,0" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="#636D6F" Grid.Column="1"/>
<TextBlock Text="{Binding shippingCost}" Height="auto" Width="auto" Margin="25,0,25,0" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="#636D6F" Grid.Column="2"/>
<TextBlock Text="{Binding totalSurcharge}" Height="auto" Width="auto" Margin="0,0,0,0" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="#009DC6" Grid.Column="3"/>
<TextBlock Text="{Binding orderStatus}" Height="auto" Width="auto" Margin="25,0,25,0" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="#636D6F" Grid.Column="4"/>
<TextBlock Text="{Binding paymentStatus}" Height="auto" Width="auto" Margin="0,0,25,0" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" Foreground="#636D6F" Grid.Column="5"/>
</Grid>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Page>
我正在使用以下代码在网络上加载 JSON 数据:
public OrderListing()
{
this.InitializeComponent();
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += navigationHelper_LoadState;
this.navigationHelper.SaveState += navigationHelper_SaveState;
loadData1();
}
private async void loadData1()
{
HttpClient http = new HttpClient();
var response = await http.GetStringAsync("http://10.0.40.117/" + "rest/admin/order/list.json");
var orderData = JsonConvert.DeserializeObject<OrderRootClass>(response);
OrderListView.ItemsSource = orderData;
}
这是订单根类:
public class OrderRootClass
{
public Order[] orders { get; set; }
}
它给出错误。我找到了一些关于此的帖子,但这无济于事。
应为 ItemsSource 属性分配 orders 集合,而不是 OrderRootClass 实例。
var orderData = JsonConvert.DeserializeObject<OrderRootClass>(response);
OrderListView.ItemsSource = orderData.orders; // here
但是,它应该给你一个编译器错误,说orderData没有实现IEnumerable。