簡體   English   中英

WPF:在元素內添加邊框

[英]WPF: Add a Border inside an element

我想知道是否可以圖片中添加邊框。 當位置設置為內部時,我想要類似Photoshop中的“筆畫”效果,即必須在圖像上繪制。 可能嗎?

謝謝。

您可以將邊框放在圖片上方:

<Grid>
 <Image/>
 <Border/>
</Grid>

如果您設置了CornerRadius ,並且想要將Image隱藏在角落中,那會更加復雜,但是您可以為Image設置另一個與OpacityMask幾乎相同的Border

<Grid>
    <!-- I used Rectangle instead of Image for the example -->
    <Rectangle Width="50" Height="50" Fill="Red">
        <Rectangle.OpacityMask>
            <VisualBrush>
                <VisualBrush.Visual>
                    <Border Width="50" Height="50" Background="Black" 
                            CornerRadius="10"/>
                </VisualBrush.Visual>
            </VisualBrush>
        </Rectangle.OpacityMask>
    </Rectangle>
</Grid>

我想那很容易

<Grid>
    <Image />
    <Border/>
</Grid>

是的,您可以采用多層方法!

<Grid>
    <Image />
    <Border horizontalAlignment="Stretch" verticalAlignment="Stretch" />
</Grid>

提醒您需要使用的屬性,這只是輕量級版本!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM