wpf textbox样式重写 文本框里的左面是一张小图片,图片右边可以输入文字,求大神写一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <Style x:Key="TextBoxStyle1" TargetType="{x:Type TextBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBox}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="40" /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Label Background="{TemplateBinding Background}"/> <Border Grid.Column="1" x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" SnapsToDevicePixels="true"> <ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </Border> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> <TextBox Width="300" Height="30" Style="{StaticResource TextBoxStyle1}"> <TextBox.Background> <ImageBrush ImageSource="图片路径" /> </TextBox.Background> </TextBox> 一定不要用#1的方式,那样的话Background只能控制图片,不能控制背景了。推荐还是写一个自定义控件,继承自TextBox,模板里面加一个元素。参考一下TextBox自己的模板和处理方式,这样做出来的东西才好通用 确实继承TextBox再写个ImageTextBox类比较好,加2个属性ImageSource,ImageWidth,然后模板加个PART_Image,这样就比较好控制了。省的麻烦就直接用上面那个模板也无所谓,个人感觉TextBox基本上不会怎么用到Background,大部分都是白色底色.难控制的也只是个图片显示宽度而已。 DataGridView绑定记录集后,如何清空里面数据 文本框设置横向滚动条为什么不行 新手提问,望高手帮忙!~感激不尽,分不够可以再加! c#.net 2003 如何获取sql2000所有数据库名呢?谢谢 各位大虾,关于Excel操作的问题,难.... 请推荐一些.NET的测试工具 asp.net的css级联样式表与用户控件的问题,欢迎大家讨论呀 C#调用Aceess数据库 怎么没有using Excel??? soft ASP.NET中如何能使Label的值传给数据库 ListView怎么换行?
<Style x:Key="TextBoxStyle1" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Label Background="{TemplateBinding Background}"/>
<Border Grid.Column="1" x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" SnapsToDevicePixels="true">
<ScrollViewer x:Name="PART_ContentHost" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style> <TextBox Width="300" Height="30" Style="{StaticResource TextBoxStyle1}">
<TextBox.Background>
<ImageBrush ImageSource="图片路径" />
</TextBox.Background>
</TextBox>
推荐还是写一个自定义控件,继承自TextBox,模板里面加一个元素。参考一下TextBox自己的模板和处理方式,这样做出来的东西才好通用