XAML:在设计时获取文件的相对路径

我正在构建一个Windows Phone 8应用程序。 在设计时,我加载一个示例XML文件以获取样本数据。 它运行良好但我想使用相对于解决方案根目录的文件路径,因此它可以适用于具有相同代码的所有开发人员。

这是我目前的代码:

var path = @"C:\Users\Tom\MyProject\SampleData\stub.xml"; xml = new StreamReader(path).ReadToEnd(); 

我尝试了一个像@“SampleData \ stub.xml”这样的相对路径。 它适用于手机但在设计时我收到此错误:

 DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\SampleData\login.xml'. 

这是我做的:

 var path = "SampleData/stub.xml"; var res = Application.GetResourceStream(new Uri(path, UriKind.Relative)) xml = new StreamReader(res.Stream).ReadToEnd();