Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to move selection by up/down key press in Treeview control in WPF and use mouse to click checkbox of treeviewitem to change the selection?

$
0
0

1. We create a HierarchicalDataTemplate for a treeview control. We can use mouse to click the tree item to change the selection. Now, we want to use keyboard up and down key to move the selection up and down. But it seems that it can't work. I searched a lot by MSDN, Google and Stackoverflow, but failed. 

2. I can use mouse to click the textblock to select the treeview item, but when I use mouse click the CheckBox, the item can't be selected (the checkbox can be checked and unchecked successfully). Is there anyway to make treeview item selected when I click the CheckBox? 

So I created a new thread for this, could you please give me some help? thx. 

<HierarchicalDataTemplate x:Uid="HierarchicalDataTemplate_1" x:Key="My_data_template" ><ContentControl x:Uid="ContentControl_1" MouseDoubleClick="MouseDoubleClick" MouseRightButtonDown="MouseRightClick"><Grid x:Uid="Grid_2" Background="Transparent"><Grid.ColumnDefinitions><ColumnDefinition x:Uid="ColumnDefinition_1" Width="*"/><ColumnDefinition x:Uid="ColumnDefinition_2" Width="Auto"/></Grid.ColumnDefinitions><StackPanel x:Uid="StackPanel_3" HorizontalAlignment="Left" Orientation="Horizontal" Grid.Column="0"><TextBlock x:Uid="TextBlock_13" Text="{Binding Name}" VerticalAlignment="Center" Margin="3,0,0,1" TextWrapping="NoWrap"/></StackPanel><CheckBox x:Uid="CheckBox_3" HorizontalAlignment="Right" Click="CheckBox_Click" Grid.Column="1" ToolTip="On/Off"></CheckBox></Grid></ContentControl></HierarchicalDataTemplate>


The way I applied the template to treeview is as following:

<TreeView   x:Name="tv_pointcloud" x:Uid="TreeListView_1" 
        ItemTemplateSelector="{StaticResource DataAccessor}" 
        ......
    />



    public class DataAccessor : DataTemplateSelector
    {
        public DataAccessor()
        {
            Init();
        }

        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var element = container as FrameworkElement;
            var template = element.FindResource("My_data_template") as DataTemplate;
            return template;
        }

        ......
    }



thanks.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>