Xaml Xamarin表单多个集合视图水平和垂直

Xaml Xamarin表单多个集合视图水平和垂直,xaml,xamarin,collectionview,Xaml,Xamarin,Collectionview,我尝试在类似这样的其他CollectionView中使用CollectionView。我的问题是那里不会显示我的第二份简历,好像那里没有一个来源。 我想BindingContex可能是个问题,但我不知道如何修复它 <CollectionView SelectionMode="Single" ItemsSource="{Binding MainInfo}"> <Collection

我尝试在类似这样的其他CollectionView中使用CollectionView。我的问题是那里不会显示我的第二份简历,好像那里没有一个来源。 我想BindingContex可能是个问题,但我不知道如何修复它

      <CollectionView 
       SelectionMode="Single"
       ItemsSource="{Binding MainInfo}">

        <CollectionView.ItemsLayout>
            <LinearItemsLayout ItemSpacing="10" Orientation="Vertical" />
        </CollectionView.ItemsLayout>

        <CollectionView.ItemTemplate>
            <DataTemplate>

                <StackLayout>

                    <Label Text="{Binding UserName}"/>

                    <!--Horizontal CV-->
                    <CollectionView 
                        SelectionMode="Single"
                        ItemsSource="{Binding MainInfo}"
                        >
                        <CollectionView.ItemsLayout>
                            <LinearItemsLayout ItemSpacing="10" Orientation="Horizontal" />
                        </CollectionView.ItemsLayout>

                        <CollectionView.ItemTemplate>
                            <DataTemplate>

                                <StackLayout>

                                    <Label Text="{Binding ImageUrl}"/>
                                    <Label Text="{Binding FullName}"/>

                                </StackLayout>

                            </DataTemplate>
                        </CollectionView.ItemTemplate>

                    </CollectionView>

                </StackLayout>

            </DataTemplate>
        </CollectionView.ItemTemplate>

    </CollectionView>

我想BindingContext可能是个问题,但我不知道如何解决它

      <CollectionView 
       SelectionMode="Single"
       ItemsSource="{Binding MainInfo}">

        <CollectionView.ItemsLayout>
            <LinearItemsLayout ItemSpacing="10" Orientation="Vertical" />
        </CollectionView.ItemsLayout>

        <CollectionView.ItemTemplate>
            <DataTemplate>

                <StackLayout>

                    <Label Text="{Binding UserName}"/>

                    <!--Horizontal CV-->
                    <CollectionView 
                        SelectionMode="Single"
                        ItemsSource="{Binding MainInfo}"
                        >
                        <CollectionView.ItemsLayout>
                            <LinearItemsLayout ItemSpacing="10" Orientation="Horizontal" />
                        </CollectionView.ItemsLayout>

                        <CollectionView.ItemTemplate>
                            <DataTemplate>

                                <StackLayout>

                                    <Label Text="{Binding ImageUrl}"/>
                                    <Label Text="{Binding FullName}"/>

                                </StackLayout>

                            </DataTemplate>
                        </CollectionView.ItemTemplate>

                    </CollectionView>

                </StackLayout>

            </DataTemplate>
        </CollectionView.ItemTemplate>

    </CollectionView>
在您的情况下,ItemsSource和model应该如下所示

    public class MyDetails
    {
        public string ImageUrl { get; set; }
        public string FullName { get; set; }
    }

    public class MyObject
    {
        public string UserName { get; set; }
        public ObservableCollection<MyDetails> MainInfo { get; set; }
    }

    public class MyViewModel: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public ObservableCollection<MyObject> MainInfo { get; set; }

        protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));        
        }

        
    }
公共类MyDetails
{
公共字符串ImageUrl{get;set;}
公共字符串全名{get;set;}
}
公共类MyObject
{
公共字符串用户名{get;set;}
公共ObservableCollection MainInfo{get;set;}
}
公共类MyViewModel:INotifyPropertyChanged
{
公共事件属性更改事件处理程序属性更改;
公共ObservableCollection MainInfo{get;set;}
受保护的虚拟void NotifyPropertyChanged([CallerMemberName]字符串propertyName=”“)
{
PropertyChanged?.Invoke(这是新的PropertyChangedEventArgs(propertyName));
}
}

此外,请同意@Jason。在您的情况下,如果希望在单元格中显示集合,可以使用而不是将CollectionView放在另一个单元格中。通过这种方式,您只需按照上述代码设置Viewmodel和model。

这样嵌套CV是个坏主意,您应该避免使用itokey。谢谢,达到相同结果的更好方法是什么?谢谢@Lucas Bindable Layouts这是我搜索的内容,但我仍然无法在da vertical Collection中使用水平集合。我需要与Instagram相同的设置StackLayouth的方向我可以接受它吗?我是StackOverlow的新手单击“✔” 在这个答案的左上角,我完全忽略了这个符号