Question

I want to make a canvas which has rounded border. I think I can implement it by OpacityMask. but it's a hard to me.

<Canvas Background="Red" ClipToBounds="True" x:Name="can">
    <Canvas.OpacityMask>
        <!--czc.png is opacity mask source which represents a rounded rectangle.-->
        <ImageBrush ImageSource="/WpfApplication3;component/Images/czc.png"/>
    </Canvas.OpacityMask>
    <Image Source="/WpfApplication3;component/Images/1lvhuman.jpg" Margin="-129,56,192,46" Canvas.Left="193" Canvas.Top="25" Height="186" Width="153" />
</Canvas>

enter image description here

figure 1. is the Image in canvas that don't hanged in the Canvas's border. In the contrary, the Image of figure 2 hanged in left border of the Canvas. when hanged in there, OpacityMask was changed.

Was it helpful?

Solution

Why are you using Canvas? Can you just use a Border with a BorderRadius instead?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top