xaml - 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>
解决方案
我相信您有自定义的 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 属性的颜色更改为灰色。
推荐阅读
- python - Apply arithmetic calculations on specific rows of a large dataframe
- python - Python中如何使用参数、函数
- python - 检测被遮挡的人脸图像
- python - 无法为 CSV 文件中的列生成正确的哈希表
- c# - C#以不同方式处理具有相同锁的两种方法
- javascript - JSON.parse 返回特定键的未定义布尔值的 JSON 字符串
- python-3.x - _tkinter.TclError:错误的窗口路径名“.!frame5”
- r - 根据 R 中 2 个变量的条件按组计算观察值
- python-3.x - Jupyter notebook 随机停止使用所有 CPU 内核
- sqlite - 为什么释放没有外部事务的保存点不会保存更改?