OctopusKing

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

初学作为记录(事发场景):

  WPFDemo的程序集中,定义了一个Views文件夹,该文件夹放一些页面Page、UI层面的东西。用Frame空间做导航的时候,始终报一个错误   //   System.IO.IOException:“找不到资源“views.buttonstylepage.xaml”。”

代码:

private void Page1_Click(object sender, RoutedEventArgs e)
        {
            if(((Button)sender).Name == "Page1")
            {
                MyFrame.Navigate(new Uri("Page1.xaml", UriKind.Relative));  //  为程序集中,文件夹之外的页面,可以找得到
            }
            else if(((Button)sender).Name == "Page2")
            {
                MyFrame.Navigate(new Uri("Views.ButtonStylePage.xaml", UriKind.Relative));  //  为文件夹内的页面,找不到
       } 
    }

原因:

  就是文件夹访问页面,用的是 . 不是/,才导致出的错  "Views.ButtonStylePage.xaml"

结果:

  将代码改为:  MyFrame.Navigate(new Uri("Views/ButtonStylePage.xaml", UriKind.Relative));

posted on 2022-04-21 00:50  八爪鱼~  阅读(270)  评论(0编辑  收藏  举报