Home > Mobile >  WPF not formatting button and text box normally
WPF not formatting button and text box normally

Time:11-01

I'm working on a WPF app, following a tutorial, and I get completely different results than his. I triple-checked my code to see if it's exactly the same as the tutorial guy's(it was), and my button just won't format correctly with the text box next to it. I expect the text box to take up 75% of the bottom of the screen, with the button taking up about 25%. Instead, the button takes up 99%, and the textbox takes up 1%. The tutorial guy's text box and button format perfectly. I'm linking the tutorial and throwing in my code below. For reference, the guy's using Visual Studio while I'm using JetBrains Rider. Does anyone know what might be causing the issue?

Link: enter image description here

CodePudding user response:

This is the cause of your problem:

<ColumnDefinition Width="2"/>

The video uses star sizing, you just forgot the asterisk '*'

<ColumnDefinition Width="2*"/>

Star sizing is a system in some WPF panels (such as grids), to let things take up a percentage of the full width. By default, the width would be "1*", so 2* is twice that -> resulting in a size of 75% for the textbox and 25% for the button (the button's column has the default width of 1*).

Currently, the column with your textbox in it is just set to 2 pixels.

CodePudding user response:

Try the following:

Change <ColumnDefinition Width="2"/> to <ColumnDefinition Width="2*"/>

You're missing *.

  • Related