【问题标题】:UWP - binding multiple grid views to a list of listsUWP - 将多个网格视图绑定到列表列表
【发布时间】:2017-03-25 10:52:26
【问题描述】:

我对如何做到这一点有点困惑。这是情况。我有一个对象的集合,自己也有一个对象的集合。我想为第一个集合中的每个对象创建一个新的网格视图,它将使用来自第二个对象的集合作为其源。

例如。在我的视图模型中,我有这样的东西

public ObservableCollection<ApiResponse> NewsStories

其中 ApiResponse 被定义为类似

public class ApiResponse
{
    public List<Article> Articles { get; set; }
}

在我制作这个列表之前,我的 xaml 类似于

<GridView ItemsSource="{Binding Articles}"
        ItemTemplate="{StaticResource GridViewTemplate }"
        IsItemClickEnabled="False"
        IsSwipeEnabled="False"
        CanDragItems="False"
        SelectionMode="Single"
        />

我能够仅绑定到单个 api 响应,并看到网格视图显示来自该响应的所有文章。但是现在我将有一个列表列表,我不确定如何继续。我尝试将其包含在列表视图中,但无济于事。

【问题讨论】:

    标签: c# xaml uwp


    【解决方案1】:

    我想我可能已经想通了。首先在我的 xaml 中我有类似的东西

    <GridView
            ItemsSource="{Binding NewsStories}"
            IsItemClickEnabled="False"
            CanDragItems="False"
            SelectionMode="None"
            ItemTemplate="{StaticResource ImageTextTemplate }">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <ItemsWrapGrid Orientation="Vertical"/>
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
        </GridView>
    

    然后在我的页面资源中

    <Page.Resources>
        <DataTemplate x:Key="ArticleTemplate"  x:DataType="data:Article">           
                <StackPanel Orientation="Vertical" Width="180" Height="240" >
                 <!-- stuff here -->
                </StackPanel>
            </StackPanel>
    
        </DataTemplate>
    
        <DataTemplate x:Key="ImageTextTemplate" x:DataType="data:ApiResponse">          
                <GridView ItemsSource="{Binding Articles}"
                    ItemTemplate="{StaticResource ArticleTemplate}"                    
                    Header="{Binding Source}" />
        </DataTemplate>
    
    </Page.Resources>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-21
      • 1970-01-01
      • 2018-08-11
      • 1970-01-01
      • 1970-01-01
      • 2017-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多