17

I want to change the just the left margin of a WPF textbox via XAML:

This code obviously does not work :

<TextBox Margin.Left ="0"/>

What would be the correct code, does anyone here know ?

Regards, MadSeb

MadSeb
  • 7,958
  • 21
  • 80
  • 121

1 Answers1

32

I can't see your code - but it would normally go like this:

<TextBox Margin="5 0 0 0"/>

First number is left, then top, then right and finally bottom margin.

Hope this helps!

Goblin
  • 7,970
  • 3
  • 36
  • 40
  • 3
    thanks for the reply...what I want to do is to change the left to 5 but without setting the top,right,bottom to 0 ! – MadSeb Sep 16 '10 at 16:59
  • 2
    i would use commas: Margin="0,0,0,0" it makes it easier to read – Muad'Dib Sep 16 '10 at 17:01
  • @MadSeb: The value is of type Thickness - which means it is a all-or-nothing setter. You can do it in code-behind tho. – Goblin Sep 16 '10 at 17:13
  • 1
    . @MuadDib: All a matter of taste - I find commas irritating :-) – Goblin Sep 16 '10 at 17:15
  • 1
    You can place the TextBlock inside a Canvas and set Canvas.Left attached property in the TextBlock. Like – Prince Ashitaka Sep 16 '10 at 18:07
  • 1
    @Avatar: Great idea! Should probably use a DockPanel instead, though to get the TextBox to fill - and set the Padding="5 0 0 0" on the DockPanel. – Goblin Sep 16 '10 at 18:14