I have a ListBox(outer) whose ListBoxItem contains a Label, ComboBox and a ListBox(inner). I want the ListBoxItem's Label and combobox to be at the their place when scrolling is done. How do I achieve this?
Please find the xaml code:
<UserControl.Resources>
<ResourceDictionary>
<DataTemplate x:Key="StageRangeListItem" DataType="ListBoxItem">
<StackPanel Orientation="Horizontal" Height="28">
<TextBox Text="{Binding Path=Min, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Label Content="-" />
<TextBox Text="{Binding Path=Max, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="DGGStageConfigurationListItem" DataType="ListBoxItem">
<StackPanel Width="100">
<StackPanel>
<Label Content="{Binding Path=GroupId.Name}" >
<Label.Style>
<Style TargetType="Label">
<Setter Property="Background" Value="{Binding Path=GroupId.RGB}" />
</Style>
</Label.Style>
</Label>
<ComboBox ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=DataContext.Photometers}" DisplayMemberPath="Name" SelectedValuePath="Id" SelectedValue="{Binding Path=PhotometerId, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<ListBox ItemsSource="{Binding Path=LightStages}" ItemTemplate="{StaticResource ResourceKey=StageRangeListItem}" Padding="-2,0,0,0" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
</ListBox>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>
Also the main xaml is as follow:
<StackPanel Orientation="Vertical" MinWidth="620" Margin="30,15,15,0">
<Label>
<Label.Content>
<TextBlock>
<Run Text="{x:Static local:Properties.Resources.LightingSetupText}" />
</TextBlock>
</Label.Content>
</Label>
<ListBox MinWidth="100" MaxWidth="625" Height="115" ItemsSource="{Binding Path=DGGStageConfigurations}" ItemTemplate="{StaticResource ResourceKey=DGGStageConfigurationListItem}" Padding="-2">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</StakPanel>
Here in the Above code...DGGStageConfiguration is the collection which in turn contains LightStages as the collection.