带前景和背景的wpf按钮作为图像

问题描述:

在我的wpf应用程序中,我有一个按钮。我希望按钮像是背景有图像,而且背景也有图像。这个怎么做?带前景和背景的wpf按钮作为图像

由于提前, 卡恩

一般情况下,你需要使用Style和/或ControlTemplate覆盖按钮的默认外观。

为例子,你可能希望看到:

随意提供更多细节或某些代码,如果(伟大的起点!)你遇到了麻烦,我们将能够进一步提供帮助。

不知道我理解你想要的这里,但这里有两个例子

的前景和背景

<Button Content="Button" FontSize="50" Margin="0,0,263,155"> 
    <Button.Background> 
     <ImageBrush ImageSource="C:\Time.png"/> 
    </Button.Background> 
    <Button.Foreground> 
     <ImageBrush ImageSource="C:\C1.png"/> 
    </Button.Foreground> 
</Button> 

alt text

相同的图像作为前景和背景

<Button Content="Button" 
     FontSize="50" 
     Foreground="{Binding RelativeSource={RelativeSource self}, Path=Background}"> 
    <Button.Background> 
     <ImageBrush ImageSource="C:\Time.png"/> 
    </Button.Background> 
</Button> 

两个不同的图像

alt text

+0

+1我忘了'ImageBrush'!这可能是所有OP的需求。 – 2010-11-05 16:53:42