【问题标题】:Dynamically Bind color to Xamarin Shape将颜色动态绑定到 Xamarin 形状
【发布时间】:2018-08-17 09:29:37
【问题描述】:

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

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

现在我正在使用代码

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

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

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

我得到错误:

未找到“FillColor”的属性、可绑定属性或事件,或者值和属性之间的类型不匹配。

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

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

【问题讨论】:

    标签: c# xaml xamarin.forms


    【解决方案1】:

    检查SSPaint 对象的the code。看来FillColor 不是可绑定属性,所以不能这样使用。你必须给它一个静态颜色。

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

    【讨论】:

      猜你喜欢
      • 2017-01-24
      • 1970-01-01
      • 2011-07-27
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 2012-08-27
      • 1970-01-01
      相关资源
      最近更新 更多