Command binding not working in NavigationItem
Hi,
I can't get the command to fire when selecting items from the navigation drawer.
Here is my XAML:
<syncfusion:SfNavigationDrawer x:Name="NavDrawer"
Position="Left"
Transition="SlideOnTop"
DrawerWidth="200"
DisplayMode="Compact"
CompactModeWidth="80"
IsToggleButtonVisible="True"
ItemClicked="NavDrawer_ItemClicked">
<syncfusion:NavigationItem Command="{Binding NavCommand}" CommandParameter="Dashboard" Header="Dashboard" Height="64" FontSize="20" FontWeight="Bold" >
<syncfusion:NavigationItem.Icon>
<materialDesign:PackIcon Kind="Home" Height="Auto" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="0" Margin="0,-20,0,-19"/>
</syncfusion:NavigationItem.Icon>
</syncfusion:NavigationItem>
<syncfusion:NavigationItem Header="Trabalhos" Height="64" FontSize="20" FontWeight="Bold" Command="{Binding NavCommand}" CommandParameter="Trabalhos">
<syncfusion:NavigationItem.Icon>
<materialDesign:PackIcon Kind="Work" Height="Auto" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="0" Margin="0,-20,0,-19" />
</syncfusion:NavigationItem.Icon>
</syncfusion:NavigationItem>
<syncfusion:NavigationItem Header="Exploração de Faturas" Height="64" FontSize="20" FontWeight="Bold" Command="{Binding NavCommand}" CommandParameter="Faturas">
<syncfusion:NavigationItem.Icon>
<materialDesign:PackIcon Kind="Invoice" Height="Auto" Width="50" HorizontalAlignment="Center" VerticalAlignment="Center" Padding="0" Margin="0,-20,0,-19" />
</syncfusion:NavigationItem.Icon>
</syncfusion:NavigationItem>
<syncfusion:SfNavigationDrawer.ContentView>
<Border>
<ContentControl Content="{Binding CurrentViewModel}" Grid.Column="1"/>
</Border>
</syncfusion:SfNavigationDrawer.ContentView>
</syncfusion:SfNavigationDrawer>
Here is my viewmodel:
public MainWindowViewModel()
{
//Commands
NavCommand = new RelayCommand<object>(OnNav);
CurrentViewModel = _dashboardViewModel;
}
private BindableBase _CurrentViewModel;
public BindableBase CurrentViewModel
{
get { return _CurrentViewModel; }
set { SetProperty(ref _CurrentViewModel, value); }
}
public RelayCommand<object> NavCommand { get; private set; }
private void OnNav(object param)
{
switch (param.ToString())
{
case "Trabalhos":
default:
CurrentViewModel = _trabalhosViewModel;
break;
case "Teste":
CurrentViewModel = _testeViewModel;
break;
case "Dashboard":
CurrentViewModel = _dashboardViewModel;
break;
case "Faturas":
CurrentViewModel = _exploradorFaturasViewModel;
break;
}
}
Any idea why it is not working?
Thanks
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
SS
Suganya Sethuraman
Syncfusion Team
January 12, 2021 11:11 AM UTC
Hi Rui,
Greetings from Syncfusion.
We have analyzed your requirement. We have prepared the sample by using Command binding in NavigationItem of SfNavigationDrawer. Please have a sample for your reference,
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/NavigationDrawerCommand-1383559996
Please check if the sample satisfies your requirement and if not provide complete runnable sample which will be helpful for us to provide the solution at the earliest.
Regards,
Suganya Sethuraman.
Greetings from Syncfusion.
We have analyzed your requirement. We have prepared the sample by using Command binding in NavigationItem of SfNavigationDrawer. Please have a sample for your reference,
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/NavigationDrawerCommand-1383559996
Please check if the sample satisfies your requirement and if not provide complete runnable sample which will be helpful for us to provide the solution at the earliest.
Regards,
Suganya Sethuraman.
Marked as answer
RU
Rui
January 13, 2021 01:33 PM UTC
Thank you for your reply.
I've realized that in fact there was a problem with how I was setting the data context of the window.
I had placed the DataContext = MainWindowViewModel; after the InitializeComponent();.
When I placed the datacontext statement before the InitializeComponent(); it worked!
SP
Sakthivel Palaniyappan
Syncfusion Team
January 14, 2021 06:53 AM UTC
Hi Rui,
Thanks for the update. Please let us know if you need further assistance on this.
Regards,
Sakthivel P.
Thanks for the update. Please let us know if you need further assistance on this.
Regards,
Sakthivel P.
SIGN IN To post a reply.