0

I am absolutely confounded by this seemingly simple error. I can't navigate to a file in the same folder using this code

NavigationService.Navigate(new Uri("Rotate.xaml", UriKind.Relative));

I also tried

NavigationService.Navigate(new Uri("/Rotate.xaml", UriKind.Relative));

However when I move the file I'm working on to the main project folder and then use this navigation code

NavigationService.Navigate(new Uri("/Pages/Rotate.xaml", UriKind.Relative));

it works! Why can't I navigate to the file when I am in the same folder but I can when I'm in the main project folder?

solution explorer

To give you a better idea here is the view of my solution explorer. This view corresponds to the first two situations. In the third situation I have the PictureSelect.xaml file outside of the Pages folder and try to navigate to the Rotate.Xaml file.

4

1 回答 1

2

I can't navigate to a file in the same folder using this code

导航器使用的路径与当前目录无关。Silverlight 中没有像 Windows 应用程序中那样的概念。

Navigator 使用该路径在 xap 中查找资源文件。因此,您总是必须使用完整路径,即使用前导正斜杠的“/Pages/Rotate.xaml”告诉 SL 开始查看根目录。

此外,BuildAction 的设置也会影响编译时文件的放置位置。

为了更好地了解这一点,解压缩 xap 文件夹,您可以看到项目的实际位置和它在哪里寻找。

有时使用相对位置似乎可行,但它很容易破坏,我避免使用它。

格雷格

于 2013-08-26T22:13:19.810 回答