Rounded Rectangle in Silverlight

The RadiusX and RadiusY properties of the Rectangle class are used to set the roundness of a rectanble. The following code creaetes a rounded rectangle.

/// <summary>

/// Creates a rounded blue rectangle with black border

/// </summary>

public void CreateARoundedRectangle()

{

    // Create a Rectangle

    Rectangle blueRectangle = new Rectangle();

    blueRectangle.Height = 100;

    blueRectangle.Width = 200;

 

    // Create a blue and a black Brush

    SolidColorBrush blueBrush = new SolidColorBrush();

    blueBrush.Color = Colors.Blue;

    SolidColorBrush blackBrush = new SolidColorBrush();

    blackBrush.Color = Colors.Black;

 

    // Set Rectangle's width and color

    blueRectangle.StrokeThickness = 4;

    blueRectangle.Stroke = blackBrush;

    // Fill rectangle with blue color

    blueRectangle.Fill = blueBrush;

 

    // Set roundness

    blueRectangle.RadiusX = 20;

    blueRectangle.RadiusY = 20;

 

    // Add Rectangle to the Grid.

    LayoutRoot.Children.Add(blueRectangle);

}

 

Next Recommended Reading Simple storyboard in silverlight

Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.