为Button 添加图片---WPF
2013-04-17 11:26
295 查看
在WPF中,让button显示为一个Image,可以设置其BackGround为Image或者Content为Image,不过这两种方法都有一些问题~~
1、可以把Button的content设置为一个Image,不过图片的周围有个边框,影响美观~
<Button>
<Image Source="" />
</Button>
2、通过设置Background,不过还是有一个边框
3、重写一个ControlTemplate,并用ImagBrush 填充一个Image
<UserControl.Resources>
<ControlTemplate x:Key="btnup" TargetType="{x:Type Button}">
<Grid>
<Rectangle HorizontalAlignment="Right" Width="11" Height="12">
<Rectangle.Fill>
<ImageBrush ImageSource="images\ico_up.png" ></ImageBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="btndown" TargetType="{x:Type Button}">
<Grid>
<Rectangle HorizontalAlignment="Right" Width="11" Height="12">
<Rectangle.Fill>
<ImageBrush ImageSource="images\ico_down.png" ></ImageBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
</UserControl.Resources>
<Button Template="{StaticResource btnup}" />
<Button Template="{StaticResource btndown}" />
1、可以把Button的content设置为一个Image,不过图片的周围有个边框,影响美观~
<Button>
<Image Source="" />
</Button>
2、通过设置Background,不过还是有一个边框
3、重写一个ControlTemplate,并用ImagBrush 填充一个Image
<UserControl.Resources>
<ControlTemplate x:Key="btnup" TargetType="{x:Type Button}">
<Grid>
<Rectangle HorizontalAlignment="Right" Width="11" Height="12">
<Rectangle.Fill>
<ImageBrush ImageSource="images\ico_up.png" ></ImageBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
<ControlTemplate x:Key="btndown" TargetType="{x:Type Button}">
<Grid>
<Rectangle HorizontalAlignment="Right" Width="11" Height="12">
<Rectangle.Fill>
<ImageBrush ImageSource="images\ico_down.png" ></ImageBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
</ControlTemplate>
</UserControl.Resources>
<Button Template="{StaticResource btnup}" />
<Button Template="{StaticResource btndown}" />
相关文章推荐
- 【WPF】Button按钮添加背景图片
- 为Button 添加图片---WPF
- WPF学习笔记——为BUTTON添加背景图片
- WPF学习笔记——为BUTTON添加背景图片
- WPF——给button添加背景图片
- WPF Button的背景图片设置
- 在Button中添加图片简单的方法
- 为WPF中TabControl的TabItem添加图片
- MFC 基础知识:对话框背景添加图片和按钮Button添加图片
- WPF C# Button 加载图片,背景图片
- android中给一个Button添加图片和文字的方法
- C#(winform)为button添加背景图片
- android:Button添加图片
- Android中在Button文本上添加图片
- MFC Ribbon中Button添加背景图片
- UCGUI中如何使用BUTTON_SetBMPEx()函数在按钮中添加图片问题
- [WPF] 为Style 里的button添加鼠标点击响应事件
- wpf 窗体添加背景图片
- WPF之路二: button添加背景图片点击后图片闪烁问题
- 给Revit中的Button添加动画和图片