Set*_*den 2 c# wpf xaml code-behind mvvm
首先,我查看了StackOverflow.com上的其他相关帖子,并且更改csproj文件中的路径并没有对此警告产生任何影响,如下所示.参考:为什么我在项目文件中找不到此警告.cs文件 还有: 如何连接xaml和xaml.cs文件
我有相当于MainWindow.xaml和MainWindow.xaml.cs.我决定将这两个文件移到Views文件夹中,因为我不喜欢我的主窗口视图与csproj文件以及App.xaml/App.xaml.cs文件一起浮动.
基本上:
查看/ MainWindow.xaml
查看/ MainWindow.xaml.cs
所以我的第一个问题:这是不允许的?我们是否需要将MainWindow.xaml和MainWindow.xaml.cs文件与csproj文件放在同一位置?
第二个问题:如果没有,那么我还缺少什么,因为我很确定我已经正确设置了所有路径?
<Page Include="Views\TimersHost.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="Views\TimersHost.xaml.cs">
<DependentUpon>Views\TimersHost.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
Run Code Online (Sandbox Code Playgroud)
我甚至将它们放在相同的标签中,因此编译器没有混淆的余地,但它仍然抱怨警告:文件'Views\TimersHost.xaml'的父文件'Views\TimersHost.xaml'在项目文件中找不到.cs'.
该警告实际上似乎表明它是MainWindow.xaml的父级是无法找到的,但从技术上讲没有父级,除非它指的是csproj文件本身,这就是为什么我问我们是否需要有MainWindow.xaml与csproj文件位于同一位置.
例如,在这篇文章中提到MainWindow.xaml应该放在Views文件夹中,这正是我想要做的: WPF中MVVM的项目结构
所以我很确定我只是遗漏了一些东西,但不知道它可能是什么,或者在哪里开始寻找.甚至我在App.xaml中的StartupUri也正确设置为指向该文件:
<Application
x:Class="TimersXP.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Views/TimersHost.xaml"
/>
Run Code Online (Sandbox Code Playgroud)
也许在TimersHost.xaml文件中我需要指定类的路径?x:Class ="Views/TimersXP.TimersHost"....这没有任何意义,并且无论如何都不起作用.
它是一个开源项目,所以这里是完整的csproj文件源:http://timersxp.codeplex.com/SourceControl/latest#VS2013/TimersXP/TimersXP.csproj (最新版本是最新的)
没有测试过,我的回答是推测性的.然而:
我会想象DependentUpon路径是相对于当前文件的路径 - 而不是您假设的项目根目录.尝试将其更改为:
<DependentUpon>TimersHost.xaml</DependentUpon>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2043 次 |
| 最近记录: |