0

在 WPF 中,我有TextBox一个BackgroundProperty设置为自定义画笔的设置。我想给这个画笔从TextBox. 画笔的GlyphRunBrush作用很像ImageBrush,但有一个光栅化字形作为画笔源。

我怎样才能做到这一点?

例子: 在此处输入图像描述

4

1 回答 1

1

一种方法是将转换应用于画笔本身,如下所示:

<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属性的宽度,但由于您将其对齐在右侧,这可能比它需要的更复杂。

于 2012-12-04T04:47:20.377 回答