I feel that I may need some converters, but this is what I want to do. I need one Image control (since it is in the data template attached to real data) with the following parameters.
- It is centered in a space equal to 90x90 (without stretching).
- Make a circular compression of a radius of 40 pixels (both horizontal and vertical).
- If the image is> 90x90, it should be placed in a 90x90 space and clamp a 40x40 circle from the middle.
- If the image is <90x90, it should be located in 90x90 space. The crop circle should not have an effect, since the entire image is contained in the clip area.
I have the XAML code below. This works, as expected, for images that are exactly 90x90 (i.e., they don't stretch, they center the image and crop). For images> 90x90, cropping works correctly, but the image is not centered. For images <90x90, the image is centered, but cropping seems to place the image in the upper left area of the image content, so the clipping clips occupy the upper left part of the image.
<Style x:Key="ImageStyle">
<Setter Property="Width" Value="90" />
<Setter Property="Height" Value="90" />
<Setter Property="Stretch" Value="None" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Clip">
<Setter.Value>
<EllipseGeometry Center="45,45" RadiusX="40" RadiusY="40" />
</Setter.Value>
</Setter>
</Style>
<Grid>
<Image Source="{Binding ImagePath}" Style="{StaticResource ImageStyle}" />
</Grid>
I can get rid of the second problem (cropping a small image) by wrapping it in a grid and moving it there, but the large material is not centered:
<Grid>
<Grid Width="90" Height="90">
<Grid.Clip>
<EllipseGeometry Center="45,45" RadiusX="40" RadiusY="40" />
</Grid.Clip>
<Image Source="{Binding ImagePath}" Style="{StaticResource ImageStyle}" />
</Grid>
</Grid>
sohum source
share