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
posted @ 2011-06-03 15:59  大气象  阅读(8919)  评论(5编辑  收藏  举报
http://www.tianqiweiqi.com