如何更改 wpf 中按钮的内容“颜色”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28555219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:57:23  来源:igfitidea点击:

How can I change the content "color" of a button in wpf

wpfbuttoncolors

提问by WasiF

<StackPanel Margin="2">
  <Button Name="btn" Click="btn_Click" Content="Load Profile Image">
    <Button.Background>
      <ImageBrush ImageSource="D:\Pictures\rectangles.jpg"></ImageBrush>
    </Button.Background>
  </Button>
</StackPanel>

Image that i am pasting here is of is almost black, so I want to change the content color to white so that it should appear properly.

我在这里粘贴的图像几乎是黑色的,所以我想将内容颜色更改为白色,以便它应该正确显示。

My apology, I hadn't added color in title which is quoted in commas, sorry for my mistake. Now it is OK, I think now it is clear to the reader ;)

我的道歉,我没有在标题中添加颜色,用逗号引用,抱歉我的错误。现在可以了,我想现在读者很清楚了 ;)

回答by Steve Mitcham

Assuming you are talking about the color of the Text you are displaying you want the Foregroundproperty.

假设您正在谈论要显示的文本的颜色,您需要该Foreground属性。

<Button Name="btn" Click="btn_Click" Content="Load Profile Image" Foreground="White">

回答by Muds

I don't think we understand what you want here coz when you provide an image as background it will become background.

我认为我们不明白您在这里想要什么,因为当您提供图像作为背景时,它将成为背景。

if you want Image , text and background to a button try this

如果你想要一个按钮的图像、文本和背景试试这个

 <Button Name="btn" Background="Red">
            <Button.Content>
                <Grid>
                    <Image Source="D:\Pictures\rectangles.jpg"></Image>
                    <TextBlock Text="Load Profile Image" ></TextBlock>
                </Grid>
            </Button.Content>
        </Button>

回答by WasiF

In case you want to change the background and foreground of a button then do this

如果您想更改按钮的背景和前景,请执行以下操作

<Button Name="btn" Content="Load Profile Image">
   <Button.Background>
      <ImageBrush ImageSource="D:\Pictures\rectangles.jpg"></ImageBrush>
   </Button.Background>
   <Button.Foreground>
   <LinearGradientBrush StartPoint="0,0" EndPoint="1,1" >
       <GradientStop Color="YellowGreen" Offset="0.25" />
       <GradientStop Color="WhiteSmoke" Offset="1.5" />
   </LinearGradientBrush>
   </Button.Foreground>
</Button>