ios - Xamarin表单-所选项目的Listview将所有背景更改为相同

标签 ios listview xamarin xamarin.ios xamarin.forms

当您选择一个项目时,所有子背景都更改为同一颜色,我发现了一个错误。

在所有元素中,我都放置了BackgroundColor属性。这仅发生在iOS中

遵循代码示例:

XAML

<ListView
        x:Name="ListPainel"
        SeparatorColor="#d2d8e2"
        SeparatorVisibility="Default"
        Margin="0"
        ItemsSource="{Binding ListPainel_Source}"
        HasUnevenRows="true"
        RefreshCommand="{Binding ListPainel_RefreshCommand}"
        IsRefreshing="{Binding ListPainel_IsRefreshing}"

    >
    </ListView>

ViewCell的一部分
        protected override void OnBindingContextChanged()
    {
        base.OnBindingContextChanged();

        dynamic temp = BindingContext;

        PainelDto painel = (PainelDto)temp;

        ...

        if(painel.HasDetalhes)
        {
            Button detalhes = new Button()
            {
                Text="VER DETALHES",
                FontSize = 12,
                TextColor = Color.FromHex("#4482ff"),
                HorizontalOptions = LayoutOptions.End,
                VerticalOptions = LayoutOptions.Start,
                HeightRequest = 20,
                WidthRequest = 120,
                BackgroundColor = Color.DeepPink
            };
            detalhes.SetBinding(
                Button.CommandProperty
                , new Binding(
                    "ViewDetalhesCommand"
                    , BindingMode.Default
                    , null
                    , null
                    , null
                    , _viewModelPainel
                )
            );
            box.Children.Add(detalhes);
        }

        ...

        View = box;
    }

未选择的项目
Unselected

所选项目
Selected

有人知道如何解决这个问题?

最佳答案

这是在iOS中选择单元格时的默认行为。

我们需要custom rendererViewCell来禁用效果。

在iOS项目中创建一个名为NativeiOSCellRenderer的类。

代码:

[assembly: ExportRenderer(typeof(ViewCell), typeof(NativeiOSCellRenderer))]
namespace FormsListViewSample.iOS
{
    class NativeiOSCellRenderer : ViewCellRenderer
    {
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            UITableViewCell cell = base.GetCell(item, reusableCell, tv);
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            return cell;      
        }
    }
}  

关于ios - Xamarin表单-所选项目的Listview将所有背景更改为相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46545737/

相关文章:

ios - “调整”我当前的 UISwipeGestureRecognizer 代码,使用 UIPanGestureRecognizer 将图像轻弹到 iPhoto 样式

WPF:带有文件夹中图像的 ListView

android - 获取 ListView 中的 ImageView 位置

java - 是否在 UI 线程上调用了 Android.App.Application Activity 生命周期回调?

mobile - Xamarin.Forms - 检测方向和调整页面

ios - 点击表格单元格时如何推送新的 View Controller ?

ios - AVPlayer 返回 nan 视频

ListView 中的 Android- ArrayAdapter 不刷新

ios - 如何使用nunit控制台指定平台(android或ios)测试

ios - 使用 PFUser.getCurrentUserInBackground() 时出错