Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use up and down key to move treeviewitem selection in WPF
    primarykey
    data
    text
    <p>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 Google and Stackoverflow, but failed. </p> <p>So I created a new thread for this, could you please give me some help? thx. </p> <pre><code>&lt;HierarchicalDataTemplate x:Uid="HierarchicalDataTemplate_1" x:Key="My_data_template" &gt; &lt;ContentControl x:Uid="ContentControl_1" MouseDoubleClick="MouseDoubleClick" MouseRightButtonDown="MouseRightClick"&gt; &lt;Grid x:Uid="Grid_2" Background="Transparent"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition x:Uid="ColumnDefinition_1" Width="*"/&gt; &lt;ColumnDefinition x:Uid="ColumnDefinition_2" Width="Auto"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;StackPanel x:Uid="StackPanel_3" HorizontalAlignment="Left" Orientation="Horizontal" Grid.Column="0"&gt; &lt;TextBlock x:Uid="TextBlock_13" Text="{Binding Name}" VerticalAlignment="Center" Margin="3,0,0,1" TextWrapping="NoWrap"/&gt; &lt;/StackPanel&gt; &lt;CheckBox x:Uid="CheckBox_3" HorizontalAlignment="Right" Click="CheckBox_Click" Grid.Column="1" ToolTip="On/Off"&gt; &lt;/CheckBox&gt; &lt;/Grid&gt; &lt;/ContentControl&gt; &lt;/HierarchicalDataTemplate&gt; </code></pre> <p>Another question is that, I can use mouse to click the textblock to select the item, but when I use mouse click the CheckBox, the item can't be selected. Is there anyway to make treeview item selected when I click the CheckBox? </p> <p>The way I applied the template to treeview is as following:</p> <pre><code>&lt;TreeView x:Name="tv_pointcloud" x:Uid="TreeListView_1" ItemTemplateSelector="{StaticResource DataAccessor}" ...... /&gt; 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; } ...... } </code></pre> <p>thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload