【问题标题】:Xamarin Forms Listview Rounded Corner Cell highlight grayoutXamarin Forms Listview 圆角单元格突出显示灰色
【发布时间】:2019-04-04 07:34:59
【问题描述】:

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

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

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

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

【问题讨论】:

  • 好吧,我有一个问题,你到底想做什么我的意思是你想要当你点击你的列表视图时,选定的项目颜色变化应该有圆形边框?我的意思是我不明白
  • @G.hakim 是的,只有 custom:RoundedCornerView 视图应该突出显示(而不是列表视图的整个视图单元格)
  • 所以你将不得不对一些事情进行更改,我会在某个时候更新答案
  • 您需要一个 ViewCell 自定义渲染器来删除默认选择颜色或将其更改为您想要的任何颜色。之后,添加一个 TapGestureRecognizer 并更改框视图 onclick 的背景颜色
  • @DuminduDeSilva - 在这里查看我的答案,它可能会帮助你stackoverflow.com/questions/25885238/…

标签: xaml xamarin xamarin.forms


【解决方案1】:

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

例如:&lt;custom:RoundedCornerView RoundedCornerRadius="12" BackgroundColor= {Binding CellColor} Margin="11,5.5,11,5.5" VerticalOptions="FillAndExpand" &gt;

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

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

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

【讨论】:

  • 感谢您的回答。在这里颜色没有改变,因为我们试图改变使用 OberverableCollection 制作的列表视图中的颜色。但我设法使用 DynamicReources 对其进行了整理。问题是一旦手指向上移动,点击事件就会触发。手指按下后我需要触发它。
猜你喜欢
  • 1970-01-01
  • 2018-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-27
  • 2021-04-23
  • 2019-02-14
  • 2014-02-21
相关资源
最近更新 更多