c# - 将颜色动态绑定(bind)到 Xamarin Shape

标签 c# xaml xamarin.forms

我在我的 Xamarin 表单项目中使用库“Stormlion.ShapeControl”(GitHub here)在 ListView 项中生成一个圆圈。

列表中的每个项目都需要为圆圈使用不同的填充颜色。

现在我正在使用代码

<shapes:Circle HeightRequest="20" WidthRequest="20">
    <shapes:Circle.Paint>
        <shapes:SSPaint x:Name="circleFillColor" FillColor="Orange"/>
    </shapes:Circle.Paint>
</shapes:Circle>

效果很好,但是当我尝试使用以下代码绑定(bind)颜色时:

<shapes:Circle HeightRequest="20" WidthRequest="20">
    <shapes:Circle.Paint>
        <shapes:SSPaint x:Name="circleFillColor" FillColor="{Binding Path=Color}"/>
    </shapes:Circle.Paint>
</shapes:Circle>

我得到错误:

No property, bindable property, or event found for 'FillColor', or mismatching type between value and property.

我也无法从后面的代码访问该属性(我假设它是 ListView 的一部分?)

如果有人能指出我正确的方向,那就太好了!

最佳答案

检查 the code SSPaint 对象。 FillColor 似乎不是可绑定(bind)的属性,因此您不能这样使用它。你必须给它一个静态颜色。

您可以创建自己的继承来解决这个问题和/或在请求此功能的 repo 上打开一个问题。似乎有人已经为 BorderColor 做了:https://github.com/stormlion227/ShapeControl.Forms/issues/1

关于c# - 将颜色动态绑定(bind)到 Xamarin Shape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51892363/

相关文章:

c# - HttpWebRequest 1个url,2个目标ip

c# - 获取按创建日期排序的 Sitecore 项目

c# - 如何以编程方式将 UWP 应用程序从后台(最小化模式)带到前台?

c# - 在运行时为动态创建的对象动态创建绑定(bind)

android - Xamarin.Forms XAML - 添加 native 控件

c# - 为什么 AuthenticationResult B2C 认证中 accessToken 为空?

c# - 存储 Wix 安装程序中用户输入的数据

wpf - 使用 XAML 停止事件冒泡

c# - 没有触发器的循环 Storyboard 动画

xamarin - 在Xamarin Forms Shared Project中将return更改为next/done键