gpt4 book ai didi

c# - DataContext 和 DesignData - 找不到文件

转载 作者:行者123 更新时间:2023-11-30 12:47:25 24 4
gpt4 key购买 nike

在我当前的布局中,我希望某些数据在设计 View 中可见,因此我阅读了有关 DataContext 和 DesignData 的内容,但我未能正确使用它们。

我的 MainPage.xaml 以这种方式启动:

<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 但没有任何效果。我还三次验证了解决方案 View 显示了目录和文件。

现在它变得有趣了:如果我将路径更改为 Source=./App.xaml,它不会提示。如果我将其更改为引用 MainPage.xaml,它会提示文件中存在一些错误。如果我将 SampleData.xml 移动到与 App.xaml 相同的根目录,它仍然拒绝找到它们...

我还将文件的构建操作更改为ResourceEmbedded ResourceDesignData,但没有任何改变。

基本上我是按照这个LongListSelector Walkthrough

有什么想法吗?

最佳答案

文件应该是Resource

如果要将文件放在项目的根目录下;除了App.xaml,只需写:

d:DataContext="{d:DesignData SampleData.xml}"

如果您想将它放在项目的文件夹中:

d:DataContext="{d:DesignData SampleData/SampleFoodData.xml}"

和它一样:

d:DataContext="{d:DesignData Source=SampleData/SampleFoodData.xml}"

关于c# - DataContext 和 DesignData - 找不到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16966311/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com