Steve Fitzsimons
Steve Fitzsimons

Reputation: 3904

NavigationView set selectedItem programmatically

How can I do this?

I have tried below but this doesn't work

NavView.SelectedItem = 1;

Upvotes: 1

Views: 2219

Answers (2)

Steve Fitzsimons
Steve Fitzsimons

Reputation: 3904

Possibly a very hacky way of doing it, is to set the x:Name property on the NavigationViewItem and then use (assign) it in the code behind.

NavView.SelectedItem = xNameOfItem;

Upvotes: 1

thezapper
thezapper

Reputation: 496

you set an index not an item. Try this => you need to add using System.Linq;

using System.Linq;
NavView.SelectedItem = NavView.MenuItems.ElementAt(YourIndex);

=> If you want to select the SettingsItem

NavView.SelectedItem = NavView.SettingsItem;

Upvotes: 10

Related Questions