ASP.NET WPF-具有角半径的图像溢出边框

时间:2019-12-23 12:49:16

标签: c# asp.net wpf image cornerradius

我在ASP.NET WPF项目中遇到问题,边界内的图像溢出边界限制。按照下面的代码:

        <Border CornerRadius="20" Grid.Column="0" Grid.Row="0"  >
            <Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
                <Image Source="{Binding ImagePath}" />
            </Button>
        </Border>

1 个答案:

答案 0 :(得分:0)

实际上,我找到了一种解决方法,可以解决这一问题,并且比以下方法更简单

  

How to make the contents of a round-cornered border be also round-cornered?

这是我的解决方法:

<Border CornerRadius="20" Grid.Column="0" Grid.Row="0">
   <Button HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch">
   </Button>
   <Border.Background>
      <ImageBrush ImageSource="{Binding UploadImage}"/>
   </Border.Background>
</Border>