当我们使用导航移动其他页面时发生错误 [英] An error is occur when we use navigation to move other page

查看:28
本文介绍了当我们使用导航移动其他页面时发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace WindowsPhoneApplication7
{
    public partial class Listbox : UserControl
    {
        public Listbox()
        {
            InitializeComponent();
        }

        private void listbox(object sender, MouseEventArgs e)
        {
            this.NavigationService.Navigate(new Uri("/home.xaml", UriKind.Relative));
        }
    }
}

发生错误.......不包含 'NavigationService' 的定义,并且找不到接受类型为 ' 的第一个参数的扩展方法 'NavigationService'(您是否缺少 using 指令或程序集引用?)

An error is occur ....... does not contain a definition for 'NavigationService' and no extension method 'NavigationService' accepting a first argument of type ' could be found (are you missing a using directive or an assembly reference?)

推荐答案

NavigationServicePhoneApplicationPage 类的一个属性.你不是从那个类派生的,你是从 UserControl 派生的.

NavigationService is a property on the PhoneApplicationPage class. You are not deriving from that class, you are deriving from UserControl.

您需要获取用户控件所在的父电话页面,并从那里获取 NavigationService 引用.

You need to get the parent phone page the user control is on and get the NavigationService reference from there.

您的编译器错误是因为它无法在您创建的 Listbox 类上找到 NavigationService 的定义.

Your compiler error is because it cannot locate a definition for NavigationService on the Listbox class you have made.

这篇关于当我们使用导航移动其他页面时发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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