My guess is that your TextBox
's container is causing it to be too large.
Try the following XAML in Kaxaml:
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBox Text="Sample text" FontSize="2" />
</Grid>
</Page>
This renders as a very small text box in the centre of the page. If you remove the VerticalAlignment="Center"
and HorizontalAlignment="Center"
from the container, then the text box is very large.
The default horizontal and vertical alignments for the Grid
and TextBox
are Stretch
, which basically means that the element doesn't care and will take what it's given. So the layout engine asks the TextBox
how big it should be and doesn't get an answer, and so the layout asks the Grid
. The Grid
doesn't care either so finally it asks the Page
/Window
, which has a fixed size, and then this size is propagated down the visual tree (taking any margins and padding into consideration along the way). The net result is that the TextBox
fills the whole area.
To prove this point, move the alignment attributes from the Grid
to the TextBox
itself. You can't see a difference visually, though if you set a background colour for the Grid you would.
<Grid Background="Red">
<TextBox VerticalAlignment="Center" HorizontalAlignment="Center"
Text="Sample text" FontSize="2" />
</Grid>
If you want to cram the text box's border right up against the text, you can also set Padding="0"
on the text box itself.
See this article for more information on the WPF layout system.