添加ListBox标头

时间:2013-12-16 08:38:39

标签: c# wpf xaml listbox

我有一个ListBox(外部),其ListBoxItem包含Label,ComboBox和ListBox(内部)。滚动完成后,我希望ListBoxItem的Label和combobox位于它们的位置。 我如何实现这一目标?

请找到xaml代码:

   <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>

主要的xaml如下:

<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>

在上面的代码中...... DGGStageConfiguration是集合,它又包含LightStages作为集合。

0 个答案:

没有答案