0

这就是我在 WPF xaml 中创建菜单的方式-

<Menu IsMainMenu="True" DockPanel.Dock="Top"  Width="auto"  TextBlock.TextAlignment="Right"   Foreground="Black"  >
    <MenuItem Header="_Sale"></MenuItem>

    <MenuItem Header="_Invoice" x:Name="Invoice" Click="Invoice_Click" ></MenuItem>
    <MenuItem Header="Purchase"></MenuItem>
    <MenuItem Header=" Inventory"></MenuItem>
    <MenuItem Header="Settings"></MenuItem>
    </Menu>

并单击此菜单的发票选项卡的事件-

public void Invoice_Click(object sender, RoutedEventArgs e)
        {
         this.NavigationService.GetNavigationService(new Invoice());

        }

我想获得已经在同一窗口中创建的 Invoice.xaml 页面,但它似乎不起作用。我已经通过教程尝试过,但仍然没有成功。

4

2 回答 2

0

this.NavigationService.GetNavigationService(new Invoice())返回NavigationService新实例化Invoice对象的 (在这里你没有将它分配给任何东西)。你想要做的是调用ofNavigate()上的方法:NavigationServicethis

public void Invoice_Click(object sender, RoutedEventArgs e)
{
    this.NavigationService.Navigate(new Invoice());
}
于 2013-07-10T07:13:56.980 回答
0

改变你的按钮点击事件代码如下

    public void Invoice_Click(object sender, RoutedEventArgs e)
    {     
     NavigationService.Navigate(new System.Uri("Invoice.xaml", UriKind.Relative));        
    }
于 2013-07-10T07:08:27.643 回答