组合框有树型视图

时间:2010-10-11 11:53:28

标签: wpf combobox

我有一个组合框,点击后会在下拉列表中显示树视图。在显示的树视图中,您可以选中和取消选中树视图项。但是,当我双击treeview项目时,我得到了组合框的可编辑文本框中显示的树视图的一部分。我不想在那里展示任何东西?如何摆脱它

这是我的XAML ..

<ComboBox Grid.Column="3" IsEditable="False" Grid.Row="1" Margin="2" ItemContainerStyle="{StaticResource ComboTreeSelectionStyle}" IsEnabled="{Binding SelectedLookIn, Converter={StaticResource LocationToTypeEnabledConverter},UpdateSourceTrigger=PropertyChanged}" MaxDropDownHeight="300" >
                            <TreeView ItemsSource="{Binding Path=SearchFilterTypes}" ItemContainerStyle="{StaticResource TreeViewItemStyle}" HorizontalContentAlignment="Stretch">
                                <TreeView.Resources>
                                    <HierarchicalDataTemplate DataType="{x:Type viewModels:SomeTypeViewModel}" ItemsSource="{Binding Path=Children}">
                                        <CheckBox Content="{Binding Path=Name}" Margin="1" IsChecked="{Binding Path=IsChecked}" />
                                    </HierarchicalDataTemplate>
                                </TreeView.Resources>
                            </TreeView>
                        </ComboBox>

1 个答案:

答案 0 :(得分:0)

您可能需要替换此组合框的控件模板,并将ContentPresenter绑定到您要显示的值:

<ControlTemplate x:Key="ExclusionsComboBoxTemplate" TargetType="{x:Type ComboBox}">
                <AdornerDecorator>
                    <Grid>
                        <ToggleButton BorderBrush="#00000000" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" Background="#00000000" Style="{x:Null}" />
                        <ToggleButton Grid.Column="2" Template="{DynamicResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>

                        <ContentPresenter HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{Binding Path=SelectedExclusionsCount}" IsHitTestVisible="False"/>

                        <TextBox Visibility="Hidden" Template="{DynamicResource ComboBoxTextBox}" HorizontalAlignment="Left" Margin="3,3,23,3" x:Name="PART_EditableTextBox" Style="{x:Null}" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/>
                        <Rectangle x:Name="DisabledVisualElement" Fill="#A5FFFFFF" RadiusX="4" RadiusY="4" IsHitTestVisible="false" Visibility="Collapsed" />
                        <Rectangle x:Name="FocusVisualElement" Margin="-1" Stroke="{DynamicResource selectedStroke}" StrokeThickness="1" RadiusX="4" RadiusY="4" IsHitTestVisible="false" Opacity="0"/>
                        <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide">
                            <Grid MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
                                <Border x:Name="DropDownBorder" Background="#FFFFFFFF" BorderBrush="{DynamicResource TextBoxNorm}" BorderThickness="1" CornerRadius="1,1,3,3">
                                    <ScrollViewer Margin="4,6,4,6"   SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
                                        <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained"/>
                                    </ScrollViewer>
                                </Border>
                            </Grid>
                        </Popup>
                    </Grid>
                </AdornerDecorator>
            </ControlTemplate>

我使用此模板在组合框中制作CheckedList,文本部分中的显示显示选择了多少项