gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 18:39:00 24 4
gpt4 key购买 nike

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

在所有元素中,我都放置了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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com