Xamarin.forms Xamarin扩展器、Collectionview和Swipeview

Xamarin.forms Xamarin扩展器、Collectionview和Swipeview,xamarin.forms,expander,swipeview,Xamarin.forms,Expander,Swipeview,我正在努力设计一个有三种不同分组的UI: 前三名 朋友 所有联系人 订阅和所有联系人将成为大名单。我的第一关如下: <Expander> <Expander.Header> <Label FontAttributes="Bold" FontSize="Medium" Text="Top 3" />

我正在努力设计一个有三种不同分组的UI:

  • 前三名
  • 朋友
  • 所有联系人
  • 订阅和所有联系人将成为大名单。我的第一关如下:

        <Expander>
        <Expander.Header>
            <Label
                FontAttributes="Bold"
                FontSize="Medium"
                Text="Top 3" />
        </Expander.Header>
        <Expander.Content>
            <CollectionView ItemsSource="{Binding MyContacts}">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <StackLayout>
                            <SwipeView>
                                <SwipeView.LeftItems>
                                    <SwipeItem BackgroundColor="Aquamarine" Text="Un Favorite" />
                                </SwipeView.LeftItems>
                                <SwipeView.Content>
                                    <Label Text="{Binding DisplayName}" />
                                </SwipeView.Content>
                            </SwipeView>
                        </StackLayout>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </Expander.Content>
    </Expander>
    <Expander>
        <Expander.Header>
            <Label
                FontAttributes="Bold"
                FontSize="Medium"
                Text="Friends" />
        </Expander.Header>
        <Expander.Content>
            <CollectionView ItemsSource="{Binding UppContacts}">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <StackLayout>
                            <SwipeView>
                                <SwipeView.LeftItems>
    
                                    <SwipeItem BackgroundColor="Brown" Text="Fav" />
    
                                </SwipeView.LeftItems>
                                <SwipeView.Content>
                                    <Label Text="{Binding DisplayName}" />
                                </SwipeView.Content>
                            </SwipeView>
                        </StackLayout>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </Expander.Content>
    </Expander>
    
    
    

    但我似乎不能在一个页面中放置多个扩展器。当我一次做一个扩展器时,所有功能都如预期一样。

    当你说页面上不能有多个扩展器时,你的意思是你收到了一条错误消息,说“属性”内容“已设置多次”之类的话

    如果是这种情况,那么您可以通过将所有扩展器包装在一个容器中来简单地解决这个问题

    例如:

    <StackLayout>
            <Expander>
                <Expander.Header>
                    <Label
                        FontAttributes="Bold"
                        FontSize="Medium"
                        Text="Top 3" />
                </Expander.Header>
                <Expander.Content>
                    <CollectionView ItemsSource="{Binding MyContacts}">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <StackLayout>
                                    <SwipeView>
                                        <SwipeView.LeftItems>
                                            <SwipeItem BackgroundColor="Aquamarine" Text="Unfavorite" />
                                        </SwipeView.LeftItems>
                                        <SwipeView.Content>
                                            <Label Text="{Binding DisplayName}" />
                                        </SwipeView.Content>
                                    </SwipeView>
                                </StackLayout>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </Expander.Content>
            </Expander>
            <Expander>
                <Expander.Header>
                    <Label
                        FontAttributes="Bold"
                        FontSize="Medium"
                        Text="Friends" />
                </Expander.Header>
                <Expander.Content>
                    <CollectionView ItemsSource="{Binding UppContacts}">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <StackLayout>
                                    <SwipeView>
                                        <SwipeView.LeftItems>
    
                                            <SwipeItem BackgroundColor="Brown" Text="Fav" />
    
                                        </SwipeView.LeftItems>
                                        <SwipeView.Content>
                                            <Label Text="{Binding DisplayName}" />
                                        </SwipeView.Content>
                                    </SwipeView>
                                </StackLayout>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </Expander.Content>
            </Expander>
        </StackLayout>
    

    当您说页面上不能有多个扩展器时,您的意思是收到错误消息,说“属性”内容“已设置多次”之类的内容吗

    如果是这种情况,那么您可以通过将所有扩展器包装在一个容器中来简单地解决这个问题

    例如:

    <StackLayout>
            <Expander>
                <Expander.Header>
                    <Label
                        FontAttributes="Bold"
                        FontSize="Medium"
                        Text="Top 3" />
                </Expander.Header>
                <Expander.Content>
                    <CollectionView ItemsSource="{Binding MyContacts}">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <StackLayout>
                                    <SwipeView>
                                        <SwipeView.LeftItems>
                                            <SwipeItem BackgroundColor="Aquamarine" Text="Unfavorite" />
                                        </SwipeView.LeftItems>
                                        <SwipeView.Content>
                                            <Label Text="{Binding DisplayName}" />
                                        </SwipeView.Content>
                                    </SwipeView>
                                </StackLayout>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </Expander.Content>
            </Expander>
            <Expander>
                <Expander.Header>
                    <Label
                        FontAttributes="Bold"
                        FontSize="Medium"
                        Text="Friends" />
                </Expander.Header>
                <Expander.Content>
                    <CollectionView ItemsSource="{Binding UppContacts}">
                        <CollectionView.ItemTemplate>
                            <DataTemplate>
                                <StackLayout>
                                    <SwipeView>
                                        <SwipeView.LeftItems>
    
                                            <SwipeItem BackgroundColor="Brown" Text="Fav" />
    
                                        </SwipeView.LeftItems>
                                        <SwipeView.Content>
                                            <Label Text="{Binding DisplayName}" />
                                        </SwipeView.Content>
                                    </SwipeView>
                                </StackLayout>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </Expander.Content>
            </Expander>
        </StackLayout>
    
    
    
    使用选项卡式页面,或使用分段控件创建选项卡式界面的幻觉。在手机屏幕上塞进太多的用户界面通常是一个坏主意。在@Timothy下,将扩展器放到另一个布局中。我似乎不能在一个页面中放置多个扩展器,你的意思是你可以在页面中添加一个扩展器?我可以使用最新的xamarin.forms版本在一个页面中添加多个扩展器。如果您可以在画图中画出您实际计划如何显示UI以及我下面的答案,这将有所帮助。同样值得注意的是,扩展器控件已移到xamarin社区工具包中。所以你可能想研究一下如何使用它。可以在这里找到:使用选项卡式页面,或使用分段控件创建选项卡式界面的幻觉。在手机屏幕上塞进太多的用户界面通常是一个坏主意。在@Timothy下,将扩展器放到另一个布局中。我似乎不能在一个页面中放置多个扩展器,你的意思是你可以在页面中添加一个扩展器?我可以使用最新的xamarin.forms版本在一个页面中添加多个扩展器。如果您可以在画图中画出您实际计划如何显示UI以及我下面的答案,这将有所帮助。同样值得注意的是,扩展器控件已移到xamarin社区工具包中。所以你可能想研究一下如何使用它。可以在这里找到: