Fit image to border background

僤鯓⒐⒋嵵緔 提交于 2021-02-17 05:46:12

问题


may i know how can fit the image into the designed border?

below are the code that i've done.

 <Border Grid.Row="1" BorderThickness="1" BorderBrush="LightGreen" Margin="20" CornerRadius="30">
            <Border.Background>
                <LinearGradientBrush EndPoint="0.504,1.5" StartPoint="0.504,0.03">
                    <GradientStop Color="#F9FFF0" Offset="0"/>
                    <GradientStop Color="#F3FFE2" Offset="0.567"/>
                </LinearGradientBrush>
            </Border.Background>
            <Image Source="/LBKIOSK;component/Resources/Images/Background/klhoho.jpg"  Opacity="0.3" Stretch="UniformToFill"/>

            <Border.Effect>
                <DropShadowEffect ShadowDepth="5" Color="#599204"></DropShadowEffect>
            </Border.Effect>
        </Border>

but output show as below , the image didn't fit inside the border


回答1:


It is possible to set the <Border.Background/> property to an <ImageBrush/> like:

<Border Grid.Row="1" BorderThickness="1" BorderBrush="LightGreen" Margin="20" CornerRadius="30">
     <Border.Background>
          <ImageBrush Stretch="UniformToFill" ImageSource="/LBKIOSK;component/Resources/Images/Background/klhoho.jpg"/>
     </Border.Background>
     <Border.Effect>
          <DropShadowEffect ShadowDepth="5" Color="#599204"></DropShadowEffect>
     </Border.Effect>
</Border>


来源:https://stackoverflow.com/questions/59083393/fit-image-to-border-background

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!