Home > Blockchain >  How to Clip a View using XAML Style?
How to Clip a View using XAML Style?

Time:11-08

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?

CodePudding user response:

@jfversluis told me that it can be achieved like this

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