【发布时间】:2018-08-08 14:12:20
【问题描述】:
我在 ViewCell 中有一个带有 2 个控件的 ListView。 1- 条目,2- 另一个带有条目的 ListView。
现在我面临着独特的问题。
案例 1:如果我点击嵌套 ListView 中的条目,我将无法点击。它的行为就像只读。
案例 2:如果我首先点击不在嵌套 ListView 内的条目,我可以专注于它。在此之后,我还可以点击/关注嵌套 ListView 内的 Entry。
这意味着我必须先点击Entry(没有嵌套的ListView),然后我才能点击或关注Entry(有嵌套的ListView)。
我在这里附加了代码请查看代码并发送适当的答案。
MainPage.Xaml
<ListView Grid.Row="1" HasUnevenRows="True" IsPullToRefreshEnabled="False"
ItemsSource="{Binding MainListViewItemSource}" CachingStrategy="RecycleElement"
ItemTapped="OnListViewItemTapped" ItemSelected="OnListViewItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<local:MyCell/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
MyCell.xaml
<Image Source="{Binding PlusMinusImage}>
<Image.GestureRecognizers>
<TapGestureRecognizer Tapped="ListOpenCommand" NumberOfTapsRequired="1"/>
</Image.GestureRecognizers>
</Image>
<StackLayout IsVisible={Binding IsVisible}>
<Label Text="Mainlabel" FontSize="15" FontFamily="Roboto" TextColor="Black"/>
<Entry x:Name="MainEntry" TextColor="Gray" Text="{Binding MainEntryValue}">
<ListView ItemsSource="{Binding MyInnerListViewItemSource}"
ItemTapped="OnListViewItemTapped" ItemSelected="OnListViewItemSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Margin="0" Text="SampleInnerText" Grid.Column="0"/>
<Entry Margin="0" Text="{Binding SampleInnerTextValue}"
Grid.Column="1"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
MainPage.xaml.cs/MyCell.xaml.cs
private void OnListViewItemSelected(object sender, SelectedItemChangedEventArgs e)
{
(sender as ListView).SelectedItem = null;
return;
}
private void OnListViewItemTapped(object sender, ItemTappedEventArgs e)
{
if (e.Item == null) return;
((ListView)sender).SelectedItem = null;
}
Android 列表视图渲染器
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (Control!=null)
{
Control.HorizontalScrollBarEnabled = false;
Control.VerticalScrollBarEnabled = false;
Control.Focusable = true;
Control.FocusableInTouchMode = true;
}
}
【问题讨论】:
-
分享你的代码,这样你就知道永远不要将列表视图相互嵌套,这被认为是一种不好的做法
-
@G.hakim 我添加了代码你能帮我解决这个问题吗?谢谢
-
你能给我一个你想要做什么的图示吗?其他一切似乎都还好
-
On image Tap stack panel visibility is set and after open it like first Focus or select main ListView and than inner ListView as I got above
-
尝试使用RepeaterView而不是listview depblog.weblogs.us/2017/09/24/xamarin-forms-repeaterview
标签: android listview xamarin xamarin.forms xamarin.android