1

I want to set Fill Color property of Ellipse via data binding, I have tried many ways so far was unsucessfull in setting it. Below is my XAML and VioewModel.cs code.

<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));
    }
}
Ovais Khan
  • 205
  • 2
  • 16

1 Answers1

1

You need to set the data context ( which is your view model with property EllipseColor)

In code behind of xaml.cs file - try setting DataContext=new ViewModel() in constructor.

rahulaga-msft
  • 3,964
  • 6
  • 26
  • 44