SOLVED

How to clip a View using XAML Style?

Copper Contributor

I have in my code several times this code

 

<Image
Aspect="AspectFit"
HeightRequest="75"
WidthRequest="75">
<Image.Clip>
<EllipseGeometry
Center="37.5,37.5"
RadiusX="37.5"
RadiusY="37.5" />
</Image.Clip>
</Image>

 

 

And I want to extract it as a XAML Style to reuse and reduce the code

It would look something like this

 

 

<Style TargetType="Image" ApplyToDerivedTypes="True" x:Key="roundedImageStyle">
<Setter Property="HeightRequest" Value="75"/>
<Setter Property="WidthRequest" Value="75"/>
<Setter Property="Aspect" Value="AspectFit"/>
<Setter Property="Clip" Value="??????"/>
</Style>

 

 

 

How can I set the Clip inside the style?

1 Reply
best response confirmed by juansturla (Copper Contributor)
Solution

@juansturla 

 

I think you should be able to do it like this:

<Setter Property="Clip">
    <EllipseGeometry
         Center="37.5,37.5"
         RadiusX="37.5"
         RadiusY="37.5" />
</Setter>
1 best response

Accepted Solutions
best response confirmed by juansturla (Copper Contributor)
Solution

@juansturla 

 

I think you should be able to do it like this:

<Setter Property="Clip">
    <EllipseGeometry
         Center="37.5,37.5"
         RadiusX="37.5"
         RadiusY="37.5" />
</Setter>

View solution in original post