xaml – Xamarin表单列表视图圆角细胞高亮灰色

我找到了一个解决方案来自定义具有圆角的点击列表视图单元格灰度

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

**这就是我所期待的!

<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>

最佳答案 我相信你有自定义的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属性的颜色更改为灰色.

点赞