Wpf treeview阻止在扩展器上单击选择

时间:2015-09-21 11:03:34

标签: wpf treeview expander

我目前仍然坚持以下问题:

我有一个自定义的TreeViewItemStyle,当我点击扩展器时,除扩展器扩展/折叠外,还会选择节点。有没有办法阻止选择展开/折叠?

 <ToggleButton x:Name="Expander" ClickMode="Press" IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
              <ToggleButton.Style>
                <Style TargetType="{x:Type ToggleButton}">
                  <Setter Property="Focusable" Value="False"/>
                  <Setter Property="Width" Value="16"/>
                  <Setter Property="Height" Value="16"/>
                  <Setter Property="Template">
                    <Setter.Value>
                      <ControlTemplate TargetType="{x:Type ToggleButton}">
                        <Border Background="Transparent" Height="16" Padding="5" Width="16">
                          <Path x:Name="ExpandPath" Data="M0,0L0,6 6,0z" Fill="Transparent" Stroke="{DynamicResource BlackBrush}">
                            <Path.RenderTransform>
                              <RotateTransform Angle="135" CenterY="3" CenterX="3"/>
                            </Path.RenderTransform>
                          </Path>
                        </Border>
                        <ControlTemplate.Triggers>
                          <Trigger Property="IsChecked" Value="True">
                            <Setter Property="RenderTransform" TargetName="ExpandPath">
                              <Setter.Value>
                                <RotateTransform Angle="180" CenterY="3" CenterX="3"/>
                              </Setter.Value>
                            </Setter>
                            <Setter Property="Fill" TargetName="ExpandPath" Value="{DynamicResource BlackBrush}"/>
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="{DynamicResource BlackBrush}"/>
                          </Trigger>
                          <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Stroke" TargetName="ExpandPath" Value="DarkGray"/>
                            <Setter Property="Fill" TargetName="ExpandPath" Value="DarkGray"/>
                          </Trigger>
                        </ControlTemplate.Triggers>
                      </ControlTemplate>
                    </Setter.Value>
                  </Setter>
                </Style>
              </ToggleButton.Style>
            </ToggleButton>

我已经尝试通过EventSetter进入PreviewMouseDown事件,但我也无法在这里找到解决方案。

0 个答案:

没有答案