NavigationBar Questions

Navigation for WPF Forum

Posted 6 years ago by Cory J. Geesaman
Version: 18.1.0672
Avatar

A couple questions in relation to events:

Is it possible to catch a click/tap of a NavigationBar button which has already been clicked (e.g. when the item is already selected in the view pane and no change is occurring?)  An alternative to this that would be better in my case would be if the selected button can be hidden outright such that it acts more like an Accordion control (e.g. expanding the active button into the view pane as it is with the header instead of having the header text plus button text duplicated and taking up space on screen.)

Tried crossing this out but strikethrough doesn't seem to want to work outside of the editor in Waterfox (based on Firefox.)  Is it possible to catch a click/tap of a NavigationBar header?  (I have a TreeListView inside of the NavigationBar - both are bound to the same data source and I'd like to be able to treat the node that acts as a category as a traversable node in itself by clearing the TreeListView selection and setting the selected item to a downstream content view to be the same source as the category item in the NavigationBar.) See follow-up comment for solution if you come across this searching for how to do it.

[Modified 6 years ago]

Comments (7)

Posted 6 years ago by Cory J. Geesaman
Avatar

For anyone that comes across this searching for how to do it, the second question was able to be resolved in my case with:

    <navigation:NavigationBar.ItemTemplate>
        <DataTemplate>
            <StackPanel x:Name="spAccordionHeader" Orientation="Horizontal" MouseDown="spAccordionHeader_OnMouseDown">
                <Image Margin="4" Source="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=navigation:NavigationBar}, Path=SelectedItem.LargeIcon}" />
                <TextBlock Text="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=navigation:NavigationBar}, Path=SelectedItem.Title}" />
            </StackPanel>
        </DataTemplate>
    </navigation:NavigationBar.ItemTemplate>
Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Cory,

1) The buttons for the panes execute the NavigationBarCommands.SelectPane command when clicked.  The NavigationBar control has a method that watches for and handles those commands.  It only changes the selection though. 

You can probably watch for button click events on the navigation bar in general like:

navBar.AddHandler(Button.ClickEvent, new RoutedEventHandler(OnButtonClick));

There isn't a way to hide the selected pane button though.

2) There isn't an event for a NavigationBarHeader click but that is a control in itself.  You could probably use another AddHandler to watch for some mouse events that occur within a NavigationBarHeader.


Actipro Software Support

Posted 6 years ago by Cory J. Geesaman
Avatar

Is it possible to hide the actively selected button outright?  Just spotted the line where you already answered this, sorry.  Would it be possible to have that ability added?  Something akin to an AccordionMode flag would be the simplest from a user standpoint I think (since that's really the only thing missing from it being a true Accordion.)

Also, on a side note: I'm not sure if you're viewing this in a browser or not but I used strikethrough over the font after posting the solution to that second question in the original post, the strikethrough doesn't show up for me outside of the editor though (using Waterfox, a Firefox derivitive.)

[Modified 6 years ago]

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Cory,

I'm not sure we want to get into hiding the selected pane button because I can foresee that leading to some usability issues with focus, layout, etc.  If you absolutely need to do it, you might be able to restyle the NavigationPane control to add support for that in its template via a trigger on the attached Selector.IsSelected property.

Thanks for the heads up on the forum strike-through not working.  We fixed that now.


Actipro Software Support

Posted 6 years ago by Cory J. Geesaman
Avatar

Where would I need to point the trigger at to hide the button?

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Cory,

You'd probably add this trigger to the NavigationPane Style:

<Trigger Property="Selector.IsSelected" Value="True">
	<Setter Property="Visibility" Value="Collapsed" />
</Trigger>


Actipro Software Support

Posted 6 years ago by Cory J. Geesaman
Avatar

Thanks, this worked perfectly.

The latest build of this product (v24.1.3) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.