Navigation Selection Changed Event

Navigation for WPF Forum

Posted 15 years ago by Nathan McCarthy
Version: 4.5.0486
Avatar
(WPF Studio, latest version)

Hi Guys,

Hopefully this will be easy to point me in the right direction.

When working with the NavigationBar I am using the SelectionChanged event to detect when a user chooses a nav Pane, which then brings up the main application window's content for that context (client data, job data etc).

I've gotten this working kind of, but am having some trouble managing the event.

1. Although the event is Changed (rather than Changing) the SelectedItem property doesn't update until after the event is fired. This doesn't seem to be the way other selectors work with the SelectionChanged event in WPF?

2. The SelectionChanged event for the NavBar fires when the selection of any NavPane's child items is changed. IE, if I have a ComboBox in the Pane's controls and the selection of the combo box is changed, the NavBar's main SelectionChanged event fires, with the Bar itself as the sender.

Is this by design? Perhaps a quirk of WPF I'm unware of?

The combination of the two behaviours is making management of events in the NavBar rather awkward and cumbersome. I get the feeling I'm writing more code than I should be, ie type checks in the selection event's added and removed items collections in order to determine exactly what is being changed ...

Am I going about this the wrong way, or is there a change needed to address the above?

[Modified at 04/15/2009 12:30 AM]

Comments (3)

Posted 15 years ago by Mike Benson - CTO, Abakos, Inc.
Avatar
I just ran into this. My workaround was to programatically bind to the SelectedPane property.

DependencyPropertyDescriptor paneChangedProperty = DependencyPropertyDescriptor.FromProperty(
                  ActiproSoftware.Windows.Controls.Navigation.NavigationBar.SelectedPaneProperty, 
                    typeof(ActiproSoftware.Windows.Controls.Navigation.NavigationBar));
if (paneChangedProperty != null)
     paneChangedProperty.AddValueChanged(this.Desktop_SideNavigationBar, this.OnPaneChanged);
                

void OnPaneChanged(object sender, EventArgs e)
{
//Your code here
}
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Nathan,

We inherit Selector for NavigationBar, and it is the class that defines the SelectionChanged event.

That being said, the SelectedPane property (I assume that's what you meant instead of SelectedItem) should have been updated before the SelectionChanged event fired. We add SelectedPane in the NavigationBar class so we've fixed it for the upcoming maintenance release.

For #2, that is how WPF works. Since both things are Selectors, the event bubbles up until it is marked as handled. That's just a quirky thing of how routed events work but is very useful in some cases.


Actipro Software Support

Posted 15 years ago by Nathan McCarthy
Avatar
Thanks the replies and the information.

Mike that looks like a nice elegant solution - certainly better than what I was working with.

Cheers!
The latest build of this product (v24.1.2) was released 0 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.