Question

I am developing a WPF application, where user has the option to navigate between the pages by clicking next / previous button or by selecting a particular page in the tree view.

<TreeView Background="Transparent" Cursor="Hand" ItemsSource="{Binding Path=TreeItems}" local:TreeViewExtensions.SelectedItemChanged="{Binding Path=SelectedItemChangedCommand}" ItemContainerStyle="{StaticResource TreeViewItemStyle}" >
     <TreeView.ItemTemplate>
          <DataTemplate>
               <TextBlock Text="{Binding DisplayName}" />
          </DataTemplate>
     </TreeView.ItemTemplate>
</TreeView>
<Button Content="&lt; Prev" Name="btnPrev" Command="{Binding Path=MovePreviousCommand}"/>
<Button Content="Next &gt;" Name="btnNext" Command="{Binding Path=MoveNextCommand}"/>

Now the problem is, when a user clicks on a particular page name, application will navigate to particular page. If the user clicks next or previous it be navigated to next or previous page. In this scenario if user clicks on the previously selected item of treeview, it will not navigate to that particular page as it is already selected.

Can anyone let me know, how to deselect the selected item of tree view when user clicks on 'Next' or 'Prev' button.

Was it helpful?

Solution

On Click of Prev or Next, you can set the selectedItem value for the treeView node to true and set focus on this node. The previously selected nodes, unselected event shall get fired.

OTHER TIPS

Use something like this to deselect selected items

<TreeView MouseLeftButtonDown="TreeView_MouseLeftButtonDown">
    <TreeViewItem Header="Employee1">
        <TreeViewItem Header="Jesper"/>
        <TreeViewItem Header="Aaberg"/>
        <TreeViewItem Header="12345"/>
    </TreeViewItem>
    <TreeViewItem Header="Employee2">
        <TreeViewItem Header="Dominik"/>
        <TreeViewItem Header="Paiha"/>
        <TreeViewItem Header="98765"/>
    </TreeViewItem>
</TreeView>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top