Hi @DotNET Fan ,
Welcome to Microsoft Q&A!
It is recommended to bind the NavigationView
, then you can get the item in ViewModel.
<core:InvokeCommandAction Command="{x:Bind ViewModel.DocumentChanged}" CommandParameter="{Binding ElementName=DocumentNavView}" />
public class TestViewModel
{
public ICommand DocumentChanged
{
get
{
return new CommadEventHandler<object>((s) => this.getContent(s));
}
}
private void getContent(object obj)
{
try
{
Microsoft.UI.Xaml.Controls.NavigationView navigationView = (Microsoft.UI.Xaml.Controls.NavigationView)obj;
Microsoft.UI.Xaml.Controls.NavigationViewItem item = navigationView.SelectedItem as Microsoft.UI.Xaml.Controls.NavigationViewItem;
Debug.WriteLine(item.Tag);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
Thank you.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.