极品分享

C# WPF TextBox 样式的使用(TextBox设置背景图片)

<Window.Resources>
<BitmapImage x:Key="UerName" CreateOptions="IgnoreImageCache" CacheOption="OnLoad" UriSource="/Test;component/Resources/UerName.jpg"/>
<Style x:Key="UserNameTemplate" TargetType="{x:Type TextBox}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TextBox">
                        <Grid>
                            <Rectangle>
                                <Rectangle.Fill>
                                    <ImageBrush Stretch="Fill" ImageSource="{DynamicResource UerName}"/>
                                </Rectangle.Fill>
                            </Rectangle>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
 
        </Style>
</Window.Resources>
<Grid>
<TextBox x:Name="textBox" Style="{StaticResource UserNameTemplate}"/>
</Grid>


2017-03-07 0 /
NET学习
/
标签: 

评论回复

回到顶部