首页 > 解决方案 > Xamarin Forms Listview 圆角单元格突出显示灰色

问题描述

我正在寻找一种解决方案来自定义带有圆角的点击列表视图单元格灰色

这就是我现在所拥有的但我需要将灰色设置为下一张图片

这就是我现在所拥有的但我需要将灰色设置为下一张图片

**这就是我所期待的!!! 这就是我所期待的!!!

<ListView ItemSelected="ItemSelected" ItemsSource="{Binding Patients}" SeparatorVisibility="None">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <custom:RoundedCornerView RoundedCornerRadius="12" Margin="11,5.5,11,5.5" VerticalOptions="FillAndExpand" >
                            <StackLayout Orientation="Vertical" BackgroundColor="White" Padding="11" >
                                <Label Text="{Binding WardName}".../>
                            </StackLayout>
                        </custom:RoundedCornerView>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>

标签: xamlxamarinxamarin.forms

解决方案


我相信您有自定义的 BackgroundColor 属性:RoundedCornerView。您可以将绑定属性分配给 BackgroundColor。

例如:<custom:RoundedCornerView RoundedCornerRadius="12" BackgroundColor= {Binding CellColor} Margin="11,5.5,11,5.5" VerticalOptions="FillAndExpand" >

在为此 ListView 绑定的模型类中,您可以拥有此属性(假设您在模型类中使用了 INotifyPropertyChanged。

    private string cellColor = "#ffffff";
public string CellColor
{
get { return cellColor;}
set { cellColor = value; OnPropertyChanged("CellColor");}
}

在 ViewModel 中,您可以有一个 ICommand 用于触发列表项点击的点击。在与 ICommand 关联的方法中,您可以使用代码将该特定列表项的 CellColor 属性的颜色更改为灰色。


推荐阅读