简体   繁体   English

如何通过绑定设置椭圆的填充颜色

[英]How to set Fill color of Ellipse via Binding

I want to set Fill Color property of Ellipse via data binding, I have tried many ways so far was unsucessfull in setting it.我想通过数据绑定设置 Ellipse 的 Fill Color 属性,到目前为止我已经尝试了很多方法都没有成功设置它。 Below is my XAML and VioewModel.cs code.下面是我的 XAML 和 VioewModel.cs 代码。

<Ellipse x:Name="ClipEllipse" Fill="{Binding EllipseColor}"></Ellipse>        

public System.Windows.Media.Color EllipseColor
{
    get
    {
        Random r = new Random();
        return System.Windows.Media.Color.FromRgb((byte)r.Next(255), (byte)r.Next(255), (byte)r.Next(255));
    }
}

You need to set the data context ( which is your view model with property EllipseColor)您需要设置数据上下文(这是具有属性 EllipseColor 的视图模型)

In code behind of xaml.cs file - try setting DataContext=new ViewModel() in constructor.在 xaml.cs 文件后面的代码中 - 尝试在构造函数中设置DataContext=new ViewModel()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM