Silverlight找不到页面错误

发布于 2024-08-11 17:47:08 字数 855 浏览 0 评论 0原文

我已经开始了一个新项目(以重构一些代码),但无法弄清楚为什么我不断收到“找不到页面/索引”错误。代码工作正常,直到我使用 add 方法(在任何集合类型上)。所以我不认为导航有问题,而是我的 IndexViewModel 类有问题。

公共部分类索引:页 { 私有 IndexViewModel _vm;

    public Index()
    {
        InitializeComponent();
        _vm = new IndexViewModel();

...

public class IndexViewModel //: ViewModelBase
    {                                         
        public SortableCollectionView Rows {get;set;}          

        public IndexViewModel()
        {
            // generate some dummy data
            Random rand = new Random();
            for (int i = 0; i < 200; i++)
            {
                Row row = new Row();
                row["stuff"] = s_names[rand.Next(s_names.Length)];

                **Rows.Add(row);**

            }
        }

I have started a a new project (to refactor some code), and just can't work out why I keep getting "Can't find page /Index" error. The code works fine until I use an add method (on any collection type). So I don't think there is a problem with the navigation, but an issue with my IndexViewModel class.

public partial class Index : Page
{
private IndexViewModel _vm;

    public Index()
    {
        InitializeComponent();
        _vm = new IndexViewModel();

...

public class IndexViewModel //: ViewModelBase
    {                                         
        public SortableCollectionView Rows {get;set;}          

        public IndexViewModel()
        {
            // generate some dummy data
            Random rand = new Random();
            for (int i = 0; i < 200; i++)
            {
                Row row = new Row();
                row["stuff"] = s_names[rand.Next(s_names.Length)];

                **Rows.Add(row);**

            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

被你宠の有点坏 2024-08-18 17:47:09

看起来您从未更新过 Rows 变量。

Rows = new SortableCollectionView();

要得到实际的错误,您可以使用从我的答案中复制的技巧 另一个问题

要查看问题所在,您需要对 MainPage.xaml.cs 进行一项更改:

// If an error occurs during navigation, show an error window
private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
    Exception ex = e.Exception;

    while (ex.InnerException != null)
    {
        ex = ex.InnerException;
    }

    e.Handled = true;
    ChildWindow errorWin = new ErrorWindow(ex);
    errorWin.Show();
}

在启动时进行更改后应用程序中,您应该看到异常而不是发生异常的页面。

Looks like you never new up your Rows variable.

Rows = new SortableCollectionView();

To get to the actual error you can use this trick copied from my answer on another question:

To see what the issue is you need to make one change to your MainPage.xaml.cs:

// If an error occurs during navigation, show an error window
private void ContentFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
    Exception ex = e.Exception;

    while (ex.InnerException != null)
    {
        ex = ex.InnerException;
    }

    e.Handled = true;
    ChildWindow errorWin = new ErrorWindow(ex);
    errorWin.Show();
}

Once you've made that change when you start the application you should see the exception instead of the page where the exception occurred.

酒解孤独 2024-08-18 17:47:09

您需要

Rows = new SortableCollectionView();

在代码中的某个地方。

You need

Rows = new SortableCollectionView();

somewhere in your code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文