放一个「;“列标题”;在WPF组合框控件模板的滚动查看器上

放一个「;“列标题”;在WPF组合框控件模板的滚动查看器上,wpf,combobox,controltemplate,columnheader,Wpf,Combobox,Controltemplate,Columnheader,以下是从该线程更新的示例项目: (VS2010.NET4.0项目) 我现在的问题是,当我有一个自定义ComboBoxItem stuff,并且默认ComboboxControlTemplate中有ItemPresenter时,如何将stackpanel horizontal之类的带有2个文本块的“列标题”添加到ScrollViewer上方的现有ComboBox ControlTemplate中 这是我现有的分组不可编辑组合框。在Scrollviewr上(12月上方…),我想要2个文本块 如何使

以下是从该线程更新的示例项目:

(VS2010.NET4.0项目)

我现在的问题是,当我有一个自定义ComboBoxItem stuff,并且默认ComboboxControlTemplate中有ItemPresenter时,如何将stackpanel horizontal之类的带有2个文本块的“列标题”添加到ScrollViewer上方的现有ComboBox ControlTemplate中

这是我现有的分组不可编辑组合框。在Scrollviewr上(12月上方…),我想要2个文本块

如何使用我的XAML代码实现这一点请参见底部:

<Window  x:Class="TestComboGrouped.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"       
        Title="MainWindow" Height="600" Width="200">
    <Window.Resources>
        <SolidColorBrush x:Key="SelectedBackgroundBrush" Color="Orange" />
        <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />

        <Style x:Key="ComboBoxItemStyle" TargetType="ComboBoxItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ComboBoxItem">
                        <Grid HorizontalAlignment="Stretch"
                      Margin="-5,0,0,0"
                      Background="{TemplateBinding Background}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="45"/>
                            </Grid.ColumnDefinitions>
                            <Border Name="border1"
                            BorderThickness="0,0,1,1"
                            BorderBrush="#FFCEDFF6"
                            Grid.Column="0">
                                <TextBlock Foreground="Purple"
                                   HorizontalAlignment="Right"
                                   Margin="0,0,5,0"
                                   Text="{Binding WeeklyLessonDate, StringFormat='yyyy-MM-dd'}"/>
                            </Border>
                            <Border Name="border2"
                            BorderThickness="0,0,1,1"
                            BorderBrush="#FFCEDFF6"
                            Grid.Column="1">
                                <TextBlock HorizontalAlignment="Center"
                                   Text="{Binding WeekNumber}"/>
                            </Border>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsHighlighted" Value="true">
                                <Setter TargetName="border1" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
                                <Setter TargetName="border2" Property="Background" Value="{StaticResource SelectedBackgroundBrush}"/>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="Foreground" Value="Red"/>
            <Style.Triggers>
                <Trigger Property="ComboBox.AlternationIndex" Value="0">
                    <Setter Property="Background" Value="White"></Setter>
                </Trigger>
                <Trigger Property="ComboBox.AlternationIndex" Value="1">
                    <Setter Property="Background" >
                        <Setter.Value>
                            <LinearGradientBrush RenderOptions.EdgeMode="Aliased" StartPoint="0.5,0.0" EndPoint="0.5,1.0">
                                <GradientStop Color="#FFFEFEFF" Offset="0"/>
                                <GradientStop Color="#FFE4F0FC" Offset="1"/>
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

        <!-- Grouped CollectionView -->
        <CollectionViewSource Source="{Binding WeeklyDateList,IsAsync=False}" x:Key="WeeklyView">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="MonthName"/>
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>

    </Window.Resources>
    <StackPanel>
        <ComboBox 
            ItemsSource="{Binding Source={StaticResource ResourceKey=WeeklyView}}"      
            ScrollViewer.HorizontalScrollBarVisibility="Auto" 
            ItemContainerStyle="{StaticResource ComboBoxItemStyle}"          
            AlternationCount="2" 
            MaxDropDownHeight="300" 
            Width="Auto" 
            x:Name="comboBox"
            >
            <ComboBox.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock 
                               Padding="5,0,0,0"
                                Background="White" 
                                Foreground="DarkBlue" 
                                FontSize="14" 
                                FontWeight="DemiBold" 
                                Text="{Binding Name}"/>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ComboBox.GroupStyle>
            <!--<ComboBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Border Style="{StaticResource ComboBoxBorderStyle}">
                            <TextBlock Width="100" Foreground="Purple"  Text="{Binding WeeklyLessonDate, StringFormat='yyyy-MM-dd'}"/>
                        </Border>
                        <Border Style="{StaticResource ComboBoxBorderStyle}">
                            <TextBlock Padding="5,0,5,0"  Width="40"   Text="{Binding WeekNumber}"/>
                        </Border>                    
                    </StackPanel>                   
                </DataTemplate>
            </ComboBox.ItemTemplate>-->   
        </ComboBox>
    </StackPanel>
</Window>


更新

好的,非常好的消息,我又找到了我的旧代码,我想我不知怎么弄丢了:)

下面是组合框的样式。我在那里贴了一些自己的xaml,看看我的评论 在下面的ControlTemplate中。这是以前组合框的列标题

我现在想要的是将这个列标题与上面的项目及其自定义ComboBoxItem合并

风格


//列头开始
//柱头端
具有列标题的组合框=>

你好,, 更新2:

这是一个列标题的代码,但垃圾弹出+滚动条不能正常工作。。。由于30000个字符的限制,我无法发布代码。哈哈,请在此处获取:


再次更新
在你的例子中也修复了它,只是改变了我下面的弹出窗口。如果来自,请下载。
此屏幕截图来自此链接


不,一点也不;-)我将向你展示我的旧组合框,我用图片更新了线程。该死的,代码背后的代码让我害怕:P我仍将等待,也许有人知道得更好。也许我可以在接下来的几天内解决上面的scrollviewer问题。如果不是,我开始悬赏,如果有人回答了,我们都学到了很多:)否则你会得到解决方案。我同意,如果你愿意,上传你的最新代码,我可以查看它已经存在了几个小时,只需向上滚动查看更新2有发送空间链接:)@Meleak你能解释一下这句话吗?目的是什么?=>为什么23??我现在明白你的问题了:)我会调查的,我已经做了它来放置列标题,但有一个很大的缺点:要么弹出窗口与数据一样长…(没有可见的滚动条),当我强制滚动条并为弹出窗口设置固定高度时,我无法滚动哈哈,现在我仍将在上面的init帖子中发布此代码。更新了我的答案,使用了代码隐藏。我不确定这是否对你有用
                            <Border x:Name="DropDownBorder" BorderBrush="DarkBlue" BorderThickness="2" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
                          // ColumnHeader START

                            <StackPanel >
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock HorizontalAlignment="Stretch" Text="lesson day" />
                                    <TextBlock HorizontalAlignment="Stretch" Text="week" />
                                </StackPanel>

                          // ColumnHeader END

                                <ScrollViewer x:Name="DropDownScrollViewer" Background="Green">
                                <Grid RenderOptions.ClearTypeHint="Enabled">
                                    <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
                                        <Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
                                    </Canvas>
                                    <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                                </Grid>
                            </ScrollViewer>
                            </StackPanel>
                        </Border>

                    </Popup>
                    <ToggleButton BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxReadonlyToggleButton}"/>
                    <ContentPresenter  ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Content="{TemplateBinding SelectionBoxItem}" ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" IsHitTestVisible="false" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                </Grid>
                <ControlTemplate.Triggers>                           

                    <Trigger Property="IsEnabled" Value="false">
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                        <Setter Property="Background" Value="#FFF4F4F4"/>
                    </Trigger>
                    <Trigger Property="IsGrouping" Value="true">
                        <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                    </Trigger>                     
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Style.Triggers>
        <Trigger Property="IsEditable" Value="true">
            <Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/>
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="IsTabStop" Value="false"/>
            <Setter Property="Padding" Value="3"/>
            <Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
        </Trigger>
    </Style.Triggers>
</Style>