Xaml 从嵌套的RepeatView获取SelectedItem
我正在使用嵌套在另一个repeaterview中的。命令RSSFeedSelectedCommand只有在顶部转发器上才能工作,这在理论上是有意义的,但我如何才能让它工作呢 我已经研究过如何使用转换器和bindtoeventcommand,但看不到它们是否能正常工作Xaml 从嵌套的RepeatView获取SelectedItem,xaml,xamarin,xamarin.forms,Xaml,Xamarin,Xamarin.forms,我正在使用嵌套在另一个repeaterview中的。命令RSSFeedSelectedCommand只有在顶部转发器上才能工作,这在理论上是有意义的,但我如何才能让它工作呢 我已经研究过如何使用转换器和bindtoeventcommand,但看不到它们是否能正常工作 <repeater:RepeaterView x:Name="MainRepeater" SeparatorHeight="25" ItemsSource={Binding Feeds}"> <repeat
<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>
如果我的假设是正确的,那么您的类结构应该是
ViewModel
|__List of Feeds
|__List of Items
|__RSSFeedSelectedCommand
因此,内部中继器控件(main repeater2
)的DataContext
将是Feed
。因此,尝试使用外部中继器控件的DataContext
。像
<repeater:RepeaterView x:Name="MainRepeater2" ItemsSource="{Binding Items}"
SelectedItemCommand="{Binding DataContext.RSSFeedSelectedCommand,
ElementName=MainRepeater}"/>
对于Xamarin:
如果我的假设是正确的,那么您的类结构应该是
ViewModel
|__List of Feeds
|__List of Items
|__RSSFeedSelectedCommand
因此,内部中继器控件(main repeater2
)的DataContext
将是Feed
。因此,尝试使用外部中继器控件的DataContext
。像
<repeater:RepeaterView x:Name="MainRepeater2" ItemsSource="{Binding Items}"
SelectedItemCommand="{Binding DataContext.RSSFeedSelectedCommand,
ElementName=MainRepeater}"/>
对于Xamarin:
中继器试图在提要中查找命令,但ViewModel中存在该命令
<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" />
中继器试图在提要中查找命令,但ViewModel中存在该命令
<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" />
是的,我的类结构是这样的,但是“ElementName”还没有为xamarin实现,我相信,请看@Bish25您是对的。你能试试这个吗<代码>
谢谢您的帮助,只是尝试了一下,仍然没有成功。还尝试在主中继器上添加InputTransparent=“true”
,但没有luck@Bish25我没有在我的机器上安装Xamarin来测试它。你能试着把DataContext={Binding}
设置成你的MainRepeater
并检查一下吗。谢谢你的帮助,帮我找到了答案。我发布了解决方案:)是的,我的类结构是这样的,但是“ElementName”还没有为xamarin实现,我相信,请看@Bish25您是对的。你能试试这个吗<代码>
谢谢您的帮助,只是尝试了一下,仍然没有成功。还尝试在主中继器上添加InputTransparent=“true”
,但没有luck@Bish25我没有在我的机器上安装Xamarin来测试它。你能试着把DataContext={Binding}
设置成你的MainRepeater
并检查一下吗。谢谢你的帮助,帮我找到了答案。我发布了解决方案:)