簡體   English   中英

如何為WPF控件的BackgroundProperty使用的筆刷留有邊距?

[英]How can a brush which is used for the BackgroundProperty of a WPF control be given a margin?

在WPF中,我有一個TextBox ,其中BackgroundProperty設置為自定義畫筆。 我想從TextBox的邊界為畫筆提供某種視覺緩沖。 筆刷是GlyphRunBrush ,其行為與ImageBrush相似,但是具有柵格化字形作為筆刷源。

我怎樣才能做到這一點?

例: 在此處輸入圖片說明

一種方法是對筆刷本身進行變換,如下所示:

<TextBox>
    <TextBox.Background>
        <ImageBrush ImageSource="/MyApp;component/Search.ico"
                    AlignmentX="Right" Stretch="Uniform">
            <ImageBrush.Transform>
                <TransformGroup>
                    <TranslateTransform X="-5"/>
                </TransformGroup>
            </ImageBrush.Transform>
        </ImageBrush>
    </TextBox.Background>
</TextBox>

您也可以嘗試更改畫筆的“ Viewport屬性的寬度,但是由於要在右側對齊,因此可能比需要的復雜。

暫無
暫無

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

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