I'm testing WPF/Silverlight on VS2012. I've found on MSDN the following code that should fill a rectangle with the RadialGradient method, but get an error "'System.Windows.Media.GradientStop' does not contain a constructor that takes 2 arguments". There are no overloads and only one available method that takes no parameters, but if so, then how would I load the values? Everywhere I research they're used with 2 parameters.
The rectangle fill works fine when it's in XAML...
(partial XAML code)...
<Rectangle.Fill>
<RadialGradientBrush>
<GradientStop Color="Black" Offset="0.063"/>
<GradientStop Color="White" Offset="1"/>
</RadialGradientBrush>
</Rectangle.Fill>
but gives an error in C#...
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Interactivity;
using Microsoft.Expression.Interactivity;
namespace Test
{
public partial class MainPage : UserControl
{
public MainPage()
{
// Required to initialize variables
InitializeComponent();
}
public void drawBars(int numBars)
{
Rectangle rectangle;
double offsetX=0;
double width=0;
for (int i = 0; i < numBars; i++)
{
RadialGradientBrush myBrush = new RadialGradientBrush();
myBrush.GradientOrigin = new Point(0.75, 0.25);
myBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0)); //error
myBrush.GradientStops.Add(new GradientStop(Colors.Orange, 0.5)); //error
myBrush.GradientStops.Add(new GradientStop(Colors.Red, 1.0)); //error
rectangle.Fill = myBrush;
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
drawBars(10);
}
}
}
I got the code from here... http://msdn.microsoft.com/en-us/library/system.windows.media.gradientstop.color.aspx
Thanks...