I start with:
I want to place the word "Discarded" on the button. I tried adding
No matter where I insert
I also want a white Foreground.
I start with:
I want to place the word "Discarded" on the button. I tried adding
No matter where I insert
I also want a white Foreground.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted May 20, 2024, 1:41 PM
The issue you’re facing is due to the fact that a
Button.Contentcan only contain one child element. In your case, you’re trying to add both aRectangleand aTextBlockas direct children ofButton.Content, which is not allowed.To solve this, you can use a
Gridor aStackPanelto contain both theRectangleand theTextBlock. Here’s how you can do it:In this code, I’ve created a custom
ControlTemplatefor theButton. Inside this template, I’ve added aGridthat contains both theRectangleand theTextBlock. TheTextBlockis centered horizontally and vertically within theGrid. TheForegroundproperty of theTextBlockis set to “White”, which will make the text appear white. TheButton’sWidthandHeightare set to “90” and “30” respectively to match the size of your originalRectangle. This should give you a rectangular button with the word “Discarded” on it. The word will be white and centered on the button.Please replace the
#444444with the actual color code you want to use for the button background. If you want to keep the gray color, you can use#444444.Thanks