0

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.

  • What does it mean "to be at their place when scrolling down" ? How is that related to the title of your question which is "Adding ListBox Header" ? – franssu Dec 16 '13 at 08:59
  • I am trying to make the label and the combobox as the header to my inner listbox – Ravi Dugar Dec 16 '13 at 09:22
  • If you want to get any help you'll have to make an effort to minimize your code to the smallest possible sample still reproducing your problem. – franssu Dec 16 '13 at 09:27
  • 1
    This is the maximum i could minimize my code – Ravi Dugar Dec 16 '13 at 09:50
  • How are we suppose to run this code ? We don't have the ViewModels you are binding to. How are we suppose to know how it does behave and how you want it to behave (we could figure it out but it would be much easier if you explained clearly : what it does / what you want it to do). – franssu Dec 16 '13 at 10:00
  • Are you looking for something that has been mentioned in link: http://stackoverflow.com/questions/14801102/wpf-scroll-itemcontrol-content-fixed-header – user1246682 Dec 17 '13 at 11:04

0 Answers0