使用按钮导航到另一个页面的NavigationWindow [英] Using a Button to navigate to another Page in a NavigationWindow

查看:241
本文介绍了使用按钮导航到另一个页面的NavigationWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用WPF导航命令框架WPF应用程序中的页面之间切换(桌面;不XBAP或Silverlight)。

I'm trying to use the navigation command framework in WPF to navigate between Pages within a WPF application (desktop; not XBAP or Silverlight).

我相信我把一切都配置正确,但它不工作。我建立并没有错误运行,我不是在输出窗口得到任何约束力的错误,但我的导航按钮是无效的。

I believe I have everything configured correctly, yet its not working. I build and run without errors, I'm not getting any binding errors in the Output window, but my navigation button is disabled.

下面是一个示例应用程序的App.xaml中:

Here's the app.xaml for a sample app:

<Application x:Class="Navigation.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="First.xaml">
</Application>

请注意中的StartupUri点First.xaml。 First.xaml是一个页面。 WPF主机会自动在NavigationWindow我的网页。下面是First.xaml:

Note the StartupUri points to First.xaml. First.xaml is a Page. WPF automatically hosts my page in a NavigationWindow. Here's First.xaml:

<Page x:Class="Navigation.First"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="First">
    <Grid>
        <Button 
            CommandParameter="/Second.xaml" 
            CommandTarget="{Binding RelativeSource=
                {RelativeSource 
                    FindAncestor, 
                    AncestorType={x:Type NavigationWindow}}}" 
            Command="NavigationCommands.GoToPage" 
            Content="Go!"/>
    </Grid>
</Page>

按钮的CommandTarget设置为NavigationWindow。该命令是GotoPage记述,页面是/Second.xaml。我试过设置CommandTarget到包含页面中,CommandParameter为Second.xaml(First.xaml和Second.xaml都在解决方案的根),我已经试过离开CommandTarget空。我也试过设置的路径结合于NavigationWindow各种导航相关的公共属性。迄今没有奏效。

The button's CommandTarget is set to the NavigationWindow. The command is GoToPage, and the page is /Second.xaml. I've tried setting the CommandTarget to the containing Page, the CommandParameter to "Second.xaml" (First.xaml and Second.xaml are both in the root of the solution), and I've tried leaving the CommandTarget empty. I've also tried setting the Path to the Binding to various navigational-related public properties on the NavigationWindow. Nothing has worked so far.

我缺少的是在这里吗?我的真正的不想做我的导航code。

What am I missing here? I really don't want to do my navigation in code.


澄清。

如果,而不是使用一个按钮,我用一个超链接:

If, instead of using a button, I use a Hyperlink:

<Grid>
    <TextBlock>
       <Hyperlink 
           NavigateUri="Second.xaml">Go!
       </Hyperlink>
    </TextBlock>
</Grid>

一切正常。然而,我的UI要求意味着使用超链接是正确的。我需要为人们preSS大的脂肪按钮。这就是为什么我要使用的按钮导航。我只是想知道我怎么能得到按钮来提供超链接不会在这种情况下,同样的能力。

everything works as expected. However, my UI requirements means that using a Hyperlink is right out. I need a big fatty button for people to press. That's why I want to use the button to navigate. I just want to know how I can get the Button to provide the same ability that the Hyperlink does in this case.

推荐答案

据该的文档,只有的DocumentViewer FlowDocumentViewer 具体实施这一命令。你需要要么找到一个导航命令 NavigationWindow 工具,或设置的CommandBinding 此命令和自己处理。

According to the documentation, only DocumentViewer and FlowDocumentViewer implement this command specifically. You'll need to either find a command for navigation that NavigationWindow implements, or set up a CommandBinding for this command and handle it yourself.

这篇关于使用按钮导航到另一个页面的NavigationWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆