关于WPF设置TextBox背景图片

beckfun beckfun 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

<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>




如上代码,背景图片是应用上了。但是运行后发现,不能输入了。bing搜索不到解决方案。只能上这里来求答案了。
代码可能不对,刚从BS转 CS (WPF)。
...全文
评论 3
收藏 已收藏
分享
返回顶部
beckfun
WPF/Silverlight 8,757 成员 12,031 内容