Не активируется контекстное меню в TreeView

Пока не щелкну по item-у TreeView, контекстное меню на пустом месте TreeView появляется но не активно.

Не активное контекстное меню

Но после щелчка по item-у в TreeView правой или левой кнопкой - все нормально, теперь по щелчку на пустом месте в TreeView контекстное меню активно.

Активное контекстное меню

С чем это может быть связано? Вот код:

            <TreeView x:Name="tv"
                      ItemsSource="{Binding Kateg}">

                <TreeView.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Node}" >
                        <Border>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="450"/>
                                    <ColumnDefinition Width="50"/>
                                    <ColumnDefinition Width="100"/>
                                </Grid.ColumnDefinitions>

                                <Grid.InputBindings>
                                    <MouseBinding Gesture="RightClick"
                                                        Command="vm:GenViewModel.PkmNode"
                                                        CommandParameter="{Binding}"/>

                                    <MouseBinding Gesture="LeftClick"
                                                        Command="vm:GenViewModel.LkmNode"
                                                        CommandParameter="{Binding}"/>
                                </Grid.InputBindings>

                                <TextBlock Name="Nap" Grid.Column="0" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock Name="KZ"  Grid.Column="1" Text="{Binding KZ, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock Name="SZ"  Grid.Column="2" Text="{Binding SZ, UpdateSourceTrigger=PropertyChanged}"/>
                            </Grid>

                            <Border.ContextMenu>
                                <ContextMenu DataContext="{StaticResource ContMenu}">
                                    <MenuItem Header="Создать" 
                                        Command="vm:GenViewModel.CreateNode" 
                                        CommandParameter="{Binding}"/>
                                    <MenuItem Header="Изменить" 
                                        Command="vm:GenViewModel.UpdateNode"
                                        CommandParameter="{Binding}"/>
                                    <MenuItem Header="Удалить" 
                                        Command="vm:GenViewModel.DeleteNode"
                                        CommandParameter="{Binding}"/>
                                </ContextMenu>

                            </Border.ContextMenu>
                        </Border>

                    </HierarchicalDataTemplate>
                </TreeView.ItemTemplate>

                <TreeView.ContextMenu>
                    <ContextMenu >
                        <MenuItem Header="Создать"
                                    Command="vm:GenViewModel.CreateNode" 
                                    CommandParameter="{Binding}"/>
                    </ContextMenu>
                </TreeView.ContextMenu>
            </TreeView>
        </Border>


   <Style TargetType="ContextMenu">
        <Setter Property="Cursor" Value="Hand"/>
        <Setter Property="Foreground" Value="{StaticResource CMI.Foreground}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ContextMenu}">
                    <Border x:Name="Border" 
                            Background="{StaticResource Background.Title}"  
                            BorderThickness="1" 
                            BorderBrush="{StaticResource CMI.BorderBrush}">
                        <StackPanel  IsItemsHost="True"/>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


        static RoutedUICommand createNode;
        public static RoutedUICommand CreateNode
        {
            get
            {
                if (createNode == null)
                    createNode = new RoutedUICommand("createNode", "CreateNode", typeof(GenViewModel));
                return createNode;
            }
        }

Ответы (0 шт):