I've looked all over and have been unable to find a solution to my problem. My entire approach might be off and I could start over if I'm simply tackling this the wrong way.
I have a WPF window with a header, a listbox, an a footer. I want to programatically add n number of user controls to the listbox and have the listbox itself be scrollable (not the entire window). I also want to turn off what happens when you click an item in the listbox (the background highlights blue - I want it to change the background of the user control now treat it as a big listbox item) Really a listbox might even be the wrong thing.
I've tried stackpanels, scrollpanels, and a half dozen other approaches. Listbox just happens to be what I'm using now. I have a dozen different types of usercontrols and based on business logic some combination of them needs to be displayed, so really I need a scrollable usercontrol container where I can determine which one, if any, has been clicked.
Here is the XAML for MainWindow.xaml
<Window x:Class="LayoutTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:customUserControls="clr-namespace:LayoutTest.Properties"
Title="Layout Sample" Height="Auto" MaxWidth="600" MinWidth="600" Width="600" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="393*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="24" TextAlignment="Center" Margin="5,5,210,5">Header</TextBlock>
<ListBox x:Name="lstPanels" Grid.Row="1" Grid.ColumnSpan="2" HorizontalContentAlignment="Stretch" Margin="0,0,0,17"/>
<TextBlock Grid.Column="1" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="24" TextAlignment="Center" Margin="5,5,210,5">Footer</TextBlock>
</Grid>
</Window>
And here is the XAML for UserControl1.xaml
<UserControl x:Class="LayoutTest.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="100" d:DesignWidth="500" Padding="0" Margin="10">
<Border BorderThickness="2" BorderBrush="OrangeRed" CornerRadius="10">
<StackPanel Orientation="Horizontal">
<Image x:Name="imgLogo" MinWidth="100" MinHeight="100" MaxWidth="100" MaxHeight="100" />
<Grid MinWidth="400">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="108*" />
<ColumnDefinition Width="104*" />
<ColumnDefinition Width="188*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="25*" />
<RowDefinition Height="35*" />
</Grid.RowDefinitions>
<TextBlock Text="xxxxx:" Margin="5,2,2,2" />
<TextBlock Grid.Column="1" Grid.ColumnSpan="2" Text="xxxxx" Margin="2" />
<TextBlock Text="xxxxx:" Grid.Row="1" Margin="5,2,2,2" />
<TextBlock Grid.Column="1" Grid.Row="1" Text="xxxxxx" Grid.ColumnSpan="2" Margin="2" />
<CheckBox Content="xxxxxx" Grid.Row="3" Name="chkSkipConfiguration" Grid.ColumnSpan="2" VerticalAlignment="Center" Margin="0,0,112,5" Width="200" HorizontalAlignment="Right" />
<Button Content="xxxxx" Grid.Column="2" Grid.Row="3" Padding="0" HorizontalAlignment="Right" Width="50" Margin="0,0,19,0" />
</Grid>
</StackPanel>
</Border>
</UserControl>
And lastly in the constructor for MainWindow.xaml.cs there is the following snippet to create 10 instances of the user control:
for(int i=0; i<10; i++)
{
lstPanels.Items.Add(new UserControl1());
}