【问题标题】:How can I change the content "color" of a button in wpf如何更改 wpf 中按钮的内容“颜色”
【发布时间】:2015-04-17 18:40:25
【问题描述】:
<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>

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

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

【问题讨论】:

  • 我不确定你在这里问什么。您的 ImageBrush 采用 ImageSource(不更改它)并将其显示为按钮的背景。如果您希望图像“更亮”,则需要更改图像的亮度。
  • 你能给我们看看这张“rectangles.jpg”图片吗?
  • 谢谢 Mike Eason 和 Lujasz Rejman。

标签: wpf button colors


【解决方案1】:

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

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

【讨论】:

  • 是的,这就是我的问题的答案。谢谢史蒂夫 :)
  • 对于多种颜色,在嵌套的TextBlock 中定义内容,其中包含每种颜色的Run 块。见:stackoverflow.com/a/29756258/2939139
【解决方案2】:

我认为我们不明白你想要什么,因为当你提供一张图片作为背景时,它会变成背景。

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

 <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>

【讨论】:

    【解决方案3】:

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

    <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>
    

    【讨论】:

      猜你喜欢
      • 2013-02-14
      • 1970-01-01
      • 2017-11-10
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      相关资源
      最近更新 更多