Hi,
I'm trying to do something quite simple.
We need to display data in a Grid inside a TabItem... We want to display the various input controls in columns that will be resized when the window is resized.
Here is a simple implementation:
<Window x:Class="Window2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window2" Height="300" Width="300"><TabControl ><TabItem x:Name="tabItem1" Header="Item #1"><ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"><Grid MinWidth="200"><Grid.ColumnDefinitions><ColumnDefinition Width="Auto" /><ColumnDefinition Width="2*" MinWidth="100"/><ColumnDefinition Width="Auto" /><ColumnDefinition Width="1*" MinWidth="100"/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="Auto" /></Grid.RowDefinitions><Label x:Name="lblTitle1" Content="Title 1" Grid.Column="0" Grid.Row="0" /><TextBox x:Name="txtValue1" Text="This is a really loooooooooooooooooooooooooong string" Grid.Column="1" Grid.Row="0" /><Label x:Name="lblTitle2" Content="Title 2" Grid.Column="2" Grid.Row="0" /><TextBox x:Name="txtValue2" Text="Value #2" Grid.Column="3" Grid.Row="0" /></Grid></ScrollViewer></TabItem></TabControl></Window>
Using this sample, the value in the textbox "txtValue1" will make the horizontal Scrollbar appear... and "Label2" and "txtValue2" will not be visible.
What we want to accomplish is to force "txtValue1" to adjust its width so the entire Grid is visible to the user (unless the available space of the Window is lesser than the sum of every column witdh).
The problem seems to lie in the fact that the content of the TabItem is render in a StackPanel (or another control) for which the MaxWidth is not the width of the window but "infinite".
Is there a solution / workaround for this problem?
Thanks.