Xamarin Forms Listview 圆角单元格高亮显示灰显

Dum*_*lva 5 xaml xamarin xamarin.forms

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

这就是我现在拥有的但我需要将灰色作为下一个图像

这就是我现在拥有的但我需要将灰色作为下一个图像

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

<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>
Run Code Online (Sandbox Code Playgroud)

has*_*mks 1

我相信您有自定义的 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");}
}
Run Code Online (Sandbox Code Playgroud)

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