I have navigation view, where i define CommandBar. In CommandBar, implemented two AppBarButton's:
<NavigationView x:Name="NavView">
<NavigationView.HeaderTemplate>
<DataTemplate>
<Grid Margin="24,10,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock
Margin="0,0,0,10"
VerticalAlignment="Bottom"
FontSize="28"
Style="{StaticResource TitleTextBlockStyle}"
Text="{Binding}" />
<CommandBar
Grid.Column="1"
Margin="0,0,10,0"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
DefaultLabelPosition="Right">
<AppBarButton
Icon="Edit"
Label="Feedback" />
<AppBarButton
Icon="OtherUser"
Label="ChangeUser" />
</CommandBar>
</Grid>
</DataTemplate>
</NavigationView.HeaderTemplate>
I would like bind that's AppBarButtons with methods in ViewModel, but i can't do that.I try make like that:
<AppBarButton
Icon="Edit"
Label="Feedback"
Click="{x:Bind ViewModel.Foo}"/>
But it's not work. On compilation appear error: Object reference not set to an instance of an object.
I'm tried add into <DataTemplate x:DataType>
, and binding to method like that:
<AppBarButton
Icon="Edit"
Label="Feedback"
Click="{x:Bind Foo}"/>
It's compiled, but on runtime is throwing exception and disappeared navigation header. Tell me please, how i can binding this AppBarButtons to my methods?