I want to have my window size to the items in the listbox. The listbox contains variable lenght strings (20 to 120 chars). When I scroll the listbox and longer strings in the listbox scroll off the display the listbox shrinks and my window shrinks with it. How can I keep my window size fixed as the user scrolls and yet still have the window initially size to content. You know, cake and eat it too.
<Window x:Class="MyApp.MyDialog
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyApp"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="My Dialog" MaxHeight="600" SizeToContent="WidthAndHeight" ShowInTaskbar="False" Width="Auto" Height="Auto" Loaded="Window_Loaded">
<Grid Width="Auto" Height="Auto" Margin="5,5,5,5">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="48" ></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" >
<TextBlock>Total: </TextBlock>
<TextBlock Text="{Binding myData.Count}"></TextBlock>
</StackPanel>
<ListBox Grid.Row="1" ItemsSource="{Binding myData}"/>
<Button Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center" Height="28" Click="buttonOK_Click" Margin="0,5,0,5" IsDefault="True" Name="buttonOK" Width="75">OK</Button>
</Grid>