Try set HorizontalAlignment="Left"
(it does not matter what kind of alignment) for StackPanel
:
<StackPanel x:Name="panel" Orientation="Horizontal" HorizontalAlignment="Left">
<TextBlock Text="Text:1" Width="90" />
<TextBox Width="90" />
</StackPanel>
At the panel width will be 180
, and all the rest controls, this value will inherit from binding (DataGrid
, TextBox
).
Quote from StackPanel MSDN:
The default value is stretch for both HorizontalAlignment and VerticalAlignment of content that is contained in a StackPanel.
Since the default alignment NaN
of panel, that panel settings Width
and Height
are inherited from parent - StackPanel
, who also has no explicit parameters. And in this panel, the width and height inherits from the Window
.