我不知道为什么,但是当我点击任何 ListView
项时,其模板中的 Button
会失去背景色。
我在 ListView
中使用默认的 ViewCell
。这是 Xamarin.Forms 错误吗?
我只在 iOS 上有这个问题。
<ListView x:Name="lv" Grid.Row="2" HasUnevenRows="true" BackgroundColor="White" ItemTapped="OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="16" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" BackgroundColor="{Binding .,Converter={StaticResource IndexColorConverter}">
<StackLayout VerticalOptions="Center">
<Label Text="{Binding Auditorium}" FontSize="18" TextColor="Black"/>
<ContentView Padding="0,-5,0,0">
<Label Text="{Binding Title}" FontSize="16" TextColor="Black"/>
</ContentView>
<StackLayout Orientation="Horizontal">
<Button WidthRequest="100" Text="{Binding ButtonOverviewText}" TextColor="White" BackgroundColor="{Binding ButtonColor}" CommandParameter="{Binding .}" Clicked="Handle_Clicked"/>
<Button WidthRequest="100" Text="{Binding ButtonOverviewText}" TextColor="White" BackgroundColor="{Binding ButtonColor}" CommandParameter="{Binding .}" Clicked="Handle_Clicked" />
</StackLayout>
</StackLayout>
<Label Text="{Binding Coordinator}" FontSize="14" TextColor="Gray"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
最佳答案
我为类似的错误提交了一个旧问题:https://bugzilla.xamarin.com/show_bug.cgi?id=27502 .
但是,您提到的特定场景是 iOS 上的预期行为,并且也发生在 native (非 Xamarin.Forms)项目中。见评论here .您可以考虑使用 UITableViewCellSelectionStyle.None
禁用单元格的 UITableViewCellSelectionStyle
。 Here是单元格渲染器的示例。您可以在此处设置 cell.SelectionStyle
。这将停止单元格的灰色突出显示。如果您不希望这样做,那么保留按钮颜色可能是一种解决方法。
关于c# - ListView Tapped 删除数据模板 Xamarin.Forms 上的按钮背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41097427/