![](/img/trans.png)
[英]How can I override the default value of a BackgroundProperty in WPF?
[英]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.