C# DataContext和DesignData-未找到文件
在我当前的布局中,我希望一些数据在设计视图中可见,因此我阅读了有关DataContext和DesignData的内容,但未能正确使用它们 My MainPage.xaml的启动方式如下:C# DataContext和DesignData-未找到文件,c#,visual-studio,xaml,windows-phone-8,C#,Visual Studio,Xaml,Windows Phone 8,在我当前的布局中,我希望一些数据在设计视图中可见,因此我阅读了有关DataContext和DesignData的内容,但未能正确使用它们 My MainPage.xaml的启动方式如下: <phone:PhoneApplicationPage x:Class="AppStalker.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://s
<phone:PhoneApplicationPage
x:Class="AppStalker.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
d:DataContext="{d:DesignData Source=./SampleData/SampleData.xml}">
我的应用程序编译时没有警告/错误,我可以在模拟器中看到数据。无论如何,在构建解决方案VS 2012后,它抱怨找不到C:\path\to\project\AppName\SampleData\SampleData.xml
我检查了三遍,确认没有输入错误,并且将xml更改为xaml,但没有任何效果。我还三次验证了Solution视图是否显示了目录和文件
现在它变得有趣了:如果我将路径更改为Source=./App.xaml
,它不会抱怨。如果我将其更改为reference MainPage.xaml,它会抱怨文件中的一些错误。如果我将我的SampleData.xml
移动到与App.xaml
相同的根目录,它仍然拒绝找到它们
我还将文件的构建操作更改为Resource
,Embedded Resource
,DesignData
,但没有任何更改
基本上我是这样的
有什么想法吗?文件应该是
Resource
如果要将文件放置在项目的根目录中;除了App.xaml
,只需写下:
d:DataContext="{d:DesignData SampleData.xml}"
如果要将其放置在项目的文件夹中:
d:DataContext="{d:DesignData SampleData/SampleFoodData.xml}"
这与:
d:DataContext="{d:DesignData Source=SampleData/SampleFoodData.xml}"
什么都不会改变。仍在抱怨找不到该文件。我已从您提供的链接下载了源代码,并更改了dataContext代码:完整源代码: