首页 > 解决方案 > 从嵌套的 RepeaterView 中获取 SelectedItem

问题描述

我正在使用嵌套在另一个中继器视图中的DottorPagliaccius 中继器视图。命令 RSSFeedSelectedCommand 除非在顶部中继器上否则不起作用,这在理论上是有道理的,但我怎样才能让它工作呢?

我已经研究过使用 Converters 和 bindtoeventcommand,但看不到让它们工作。

<repeater:RepeaterView x:Name="MainRepeater" SeparatorHeight="25" ItemsSource={Binding Feeds}">
    <repeater:RepeaterView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Spacing="10">
                    <Label Text="{Binding Title}" TextColor="Blue" />
                    <Label Text="{Binding Description}" TextColor="Red" FontSize="12" />
                    <repeater:RepeaterView x:Name="MainRepeater2" EmptyText="No elements" ShowSeparator="true" SeparatorHeight="2" SeparatorColor="Silver" ItemsSource="{Binding Items}" SelectedItemCommand="{Binding RSSFeedSelectedCommand}">
                        <repeater`enter code here`:RepeaterView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <StackLayout Orientation="Horizontal">
                                        <Image Source="{Binding Image.Url}"></Image>
                                        <StackLayout Orientation="Vertical">
                                            <Label Text="{Binding Title}" TextColor="Black" />
                                            <Label Text="{Binding Description}" TextColor="Black" FontSize="12" />
                                        </StackLayout>
                                    </StackLayout>
                                </ViewCell>
                            </DataTemplate>
                        </repeater:RepeaterView.ItemTemplate>
                    </repeater:RepeaterView>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </repeater:RepeaterView.ItemTemplate>
</repeater:RepeaterView>

标签: xamlxamarinxamarin.forms

解决方案


中继器试图在其中找到命令,Feeds但视图模型中存在。

<repeater:RepeaterView x:Name="MainRepeater2" EmptyText="No elements" ShowSeparator="true" SeparatorHeight="2" SeparatorColor="Silver" ItemsSource="{Binding Items}" SelectedItemCommand="{Binding Source={x:Reference RSSPage}, Path=BindingContext.RSSFeedSelectedCommand}">

你必须命名页面:

<ContentPage x:Name="PageName" />

推荐阅读