2010-10-11 119 views
2

我有一個組合框,單擊它時會在下拉菜單中顯示一個樹形視圖。在顯示的樹視圖中,您可以選中並取消選中樹視圖項目。但是,當我雙擊樹視圖項目時,我將獲得顯示在組合框的可編輯文本框中的樹視圖的一部分。我不想在那裏顯示任何東西?如何擺脫它樹形視圖組合框

這裏是我的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> 
+0

請發表您的XAML。否則,你得到的答案將是一個猜測。 – 2010-10-11 14:24:15

回答

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的組合框,文本部分顯示的顯示有多少項被選中

+0

我不想更改模板,因爲我想要獨立於主題的控件。有什麼建議嗎? – Dheena 2010-10-12 05:22:20

+0

你的意思是我的例子中有主題信息,然後刪除它。如果你想避免維護兩個控件模板,那麼我沒有其他解決方案 – benPearce 2010-10-12 07:31:14