C# 需要帮助将XAML转换为C代码吗?

C# 需要帮助将XAML转换为C代码吗?,c#,xaml,C#,Xaml,我给你举个例子 这: 以下是您的第一个椭圆的代码: Rectangle rectangle = new Rectangle(); rectangle.Width = 200; rectangle.Height = 100; // Create a diagonal linear gradient with four stops. LinearGradientBrush brush = new LinearGradientBrush(); brush.StartPoint = new Po

我给你举个例子

这:


以下是您的第一个椭圆的代码:

Rectangle rectangle = new Rectangle();
rectangle.Width = 200;
rectangle.Height = 100;

// Create a diagonal linear gradient with four stops.   
LinearGradientBrush brush = new LinearGradientBrush();
brush.StartPoint = new Point(0,0);
brush.EndPoint = new Point(1,1);
brush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0));
brush.GradientStops.Add(new GradientStop(Colors.Red, 0.25));                
brush.GradientStops.Add(new GradientStop(Colors.Blue, 0.75));        
brush.GradientStops.Add(new GradientStop(Colors.LimeGreen, 1.0));

// Use the brush to paint the rectangle.
rectangle.Fill = brush;
你可以很容易地在同一条线上做第二个

编辑:如果您是新用户,则第二个椭圆中附加的画布属性可能会变得棘手,因此以下是如何设置它们:

RadialGradientBrush radialGradientBrush =
    new RadialGradientBrush
        {
            GradientOrigin = new Point(.5, .8),
            RadiusX = 0.6
        };

radialGradientBrush.GradientStops.Add(
    new GradientStop
        {
            Color = ((Color) ColorConverter.ConvertFromString("#002255")),
            Offset = 1
        });
radialGradientBrush.GradientStops.Add(
    new GradientStop
        {
            Color = ((Color) ColorConverter.ConvertFromString("#00eeff")),
            Offset = 0
        });

Ellipse firstEllipse =
    new Ellipse {Width = 24, Height = 24, Margin = new Thickness(10), Fill = radialGradientBrush};
Rectangle rectangle = new Rectangle();
rectangle.Width = 200;
rectangle.Height = 100;

// Create a diagonal linear gradient with four stops.   
LinearGradientBrush brush = new LinearGradientBrush();
brush.StartPoint = new Point(0,0);
brush.EndPoint = new Point(1,1);
brush.GradientStops.Add(new GradientStop(Colors.Yellow, 0.0));
brush.GradientStops.Add(new GradientStop(Colors.Red, 0.25));                
brush.GradientStops.Add(new GradientStop(Colors.Blue, 0.75));        
brush.GradientStops.Add(new GradientStop(Colors.LimeGreen, 1.0));

// Use the brush to paint the rectangle.
rectangle.Fill = brush;
RadialGradientBrush radialGradientBrush =
    new RadialGradientBrush
        {
            GradientOrigin = new Point(.5, .8),
            RadiusX = 0.6
        };

radialGradientBrush.GradientStops.Add(
    new GradientStop
        {
            Color = ((Color) ColorConverter.ConvertFromString("#002255")),
            Offset = 1
        });
radialGradientBrush.GradientStops.Add(
    new GradientStop
        {
            Color = ((Color) ColorConverter.ConvertFromString("#00eeff")),
            Offset = 0
        });

Ellipse firstEllipse =
    new Ellipse {Width = 24, Height = 24, Margin = new Thickness(10), Fill = radialGradientBrush};
Canvas.SetTop(secondEllipse, 1);
Canvas.SetLeft(secondEllipse, 3);