WPF设置Button背景
生活随笔
收集整理的這篇文章主要介紹了
WPF设置Button背景
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一個方法是把Button的Content設置為<Image/>
另一個方法是設置Button的Style屬性。
<Window?x:Class="WpfApp.Window1"
????????xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
????????xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
????????Title="http://dotnet.5d6d.com"?Height="384"?Width="614">
????<Grid>
????????<Button?Height="140"?HorizontalAlignment="Left"?Margin="10,10,0,0"?VerticalAlignment="Top"?Width="140">
????????????<Image?Source="img/bg1.jpg"></Image>
????????</Button>
????????<Button?Style="{DynamicResource?btnTemp}">hi</Button>
????</Grid>
????<Window.Resources>
????????<Style?x:Key="btnTemp"?TargetType="{x:Type?Button}">
????????????<Setter?Property="Control.Background"?Value="blue"></Setter>
????????????<Setter?Property="Control.Margin"?Value="160,10,0,0"></Setter>
????????????<Setter?Property="Control.Width"?Value="140"></Setter>
????????????<Setter?Property="Control.Height"?Value="140"></Setter>
????????????<Setter?Property="Control.HorizontalAlignment"?Value="Left"></Setter>
????????????<Setter?Property="Control.VerticalAlignment"?Value="Top"></Setter>
????????</Style>
????</Window.Resources>
</Window>SEOhttp://greatverve.cnblogs.com/archive/2011/06/03/button-background.html
另一個方法是設置Button的Style屬性。
<Window?x:Class="WpfApp.Window1"
????????xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
????????xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
????????Title="http://dotnet.5d6d.com"?Height="384"?Width="614">
????<Grid>
????????<Button?Height="140"?HorizontalAlignment="Left"?Margin="10,10,0,0"?VerticalAlignment="Top"?Width="140">
????????????<Image?Source="img/bg1.jpg"></Image>
????????</Button>
????????<Button?Style="{DynamicResource?btnTemp}">hi</Button>
????</Grid>
????<Window.Resources>
????????<Style?x:Key="btnTemp"?TargetType="{x:Type?Button}">
????????????<Setter?Property="Control.Background"?Value="blue"></Setter>
????????????<Setter?Property="Control.Margin"?Value="160,10,0,0"></Setter>
????????????<Setter?Property="Control.Width"?Value="140"></Setter>
????????????<Setter?Property="Control.Height"?Value="140"></Setter>
????????????<Setter?Property="Control.HorizontalAlignment"?Value="Left"></Setter>
????????????<Setter?Property="Control.VerticalAlignment"?Value="Top"></Setter>
????????</Style>
????</Window.Resources>
</Window>SEOhttp://greatverve.cnblogs.com/archive/2011/06/03/button-background.html
轉載于:https://www.cnblogs.com/greatverve/archive/2011/06/03/button-background.html
總結
以上是生活随笔為你收集整理的WPF设置Button背景的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 风客科技网管培训资料
- 下一篇: 弹出模态窗口,关闭并刷新页面