组合框有树视图 [英] Combo box with a tree view

查看:123
本文介绍了组合框有树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a combobox which when clicked will show a treeview in the drop down. In the displayed tree view you can check and uncheck treeview items. But when I double click on treeview items I am getting a part of tree view displayed in the editable text box of the combobox. I dont want anything to be displayed there? How to get rid of it

这是我的XAML ..

here's my 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>


推荐答案

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

You will probably need to replace your control template for this combo box and bind the ContentPresenter to the value you want to display:

<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,文本部分的显示显示已选择许多项目

I have used this template to make a CheckedList in a combobox, the display in the text section displays how many items are selected

这篇关于组合框有树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆