(X) Hide this
    • Login
    • Join
      • Generate New Image
        By clicking 'Register' you accept the terms of use .

Tip: How to add an oval clip to a control

(0 votes)
Martin Mihaylov
>
Martin Mihaylov
Joined Oct 29, 2007
Articles:   50
Comments:   70
More Articles
1 comments   /   posted on Sep 05, 2008
Categories:   Controls

If you want to add an oval clip to your control, you can do it the following way:

Xaml

<Button x:Name="MyButton" Content="Click me!" Width="80" Height="30">
    <Button.Clip>
        <EllipseGeometry RadiusX="35" RadiusY="13" Center="40,15"></EllipseGeometry>
    </Button.Clip>
</Button>

C#

EllipseGeometry myClip = new EllipseGeometry();
myClip.Center = new Point( MyButton.Width / 2, MyButton.Height / 2 );
myClip.RadiusX = MyButton.Width / 2;
myClip.RadiusY = MyButton.Height / 2;
 
MyButton.Clip = myClip;

For the example we use a button. We set the clip using the System.Windows.Media.EllipseGeometry object. The center is in relation to the size of the button. In this case we have a button with height 30 and width 80. The center of the button will be with coordinates (40,15). We set the center of the clip to the center of the rectangle. Of course we can set it anywhere we want. We use the RadiusX and RadiusY properties to define the size.

Without clip

With clip

That's it!


Subscribe

Comments

  • -_-

    RE: Tip: How to add an oval clip to a control


    posted by lan-xxx on Oct 22, 2010 22:09
    nice !

Add Comment

Login to comment:
  *      *