0

I have the following code:

var cellButton = new Button( ) { Background = new SolidColorBrush( 
Colors.Transparent ), BorderThickness = new Thickness( 0 ) };

Then I have a stackpanel

var stack = new StackPanel( ) { Orientation = Orientation.Vertical, 
VerticalAlignment= VerticalAlignment.Stretch, HorizontalAlignment= 
HorizontalAlignment.Stretch };

cellButton.Content = stack;

The button is the problem here. This seems to have no affect at all, am I doing something wrong? I can still see the default Boder and Default background(Gray) of the button. I even tried to change the color to something else, nothing.

So as you can see I had to strecht the stackpanel horizontal and vertical to overtake the buttons background as a dirty solution, but I can still see the border of the button.

4
  • Did you try setting the border opacity to 0? Commented Sep 8, 2017 at 10:35
  • Why are you setting the Content of the Button to an empty StackPanel? Commented Sep 8, 2017 at 10:36
  • In my code its not empty, I just didnt want to post all the code for the stackpanel. The background of the stackpane is white. And streching the stackpanel helps Commented Sep 8, 2017 at 11:20
  • So what is your issue? Commented Sep 8, 2017 at 11:55

1 Answer 1

1

Are you 100% sure that what you see on the screen is the Button created by the code you have posted here? Not only it would be transparent and have no content, since you have set Button.Content to an empty StackPanel, but it will have Height=auto and Width=auto (by default), so in this case it will be set to 0.

Try setting your Button.Background and Button.BorderBrush to another color (e.g. red) to test if it works. Also set Button.Width and Button.Height to hardcoded values just for testing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.