【发布时间】:2023-10-24 05:35:01
【问题描述】:
我最初在 MVVM Light CodePlex 页面上发布了这条消息,但还没有收到回复,所以我希望这里有人可以帮助我。问题来了:
我最近开始使用 MVVM(也是 WPF 的新手——所有这一切的学习曲线都相当不错),在我开始使用 CodePlex 上提供的 MetroToolkit 之前,我的 ViewModelLocator 实例和 VS2010 的绑定设计时一切都很好。在使用该工具包之前,我有以下内容:
<Application.Resources>
<local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</Application.Resources>
我所有的观点都很好,一切看起来都很好。我很惊讶没有 MVVM(或 MVC)经验的人可以轻松启动和运行。然后我遇到了需要合并资源字典的 MetroToolkit 的障碍,现在无论我尝试什么,我都无法让 VS 在 App.xaml 中再次找到我的 ViewModelLocator。这是新的标记:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Colors.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Animations.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Geometry.xaml"/>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Generic.xaml"/>
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Buttons.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollbar.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Scrollviewer.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/RadioButton.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ProgressBar.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/ContextMenu.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Tooltip.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Checkbox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Headings.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Textbox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Combobox.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Slider.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/Expander.xaml" />
<ResourceDictionary Source="/MetroToolkit;component/Themes/Dark/TabControl.xaml" />
</ResourceDictionary.MergedDictionaries>
<local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</ResourceDictionary>
</Application.Resources>
我尝试为资源字典提供一个键,在该区域之外添加行(上方和下方 - 引发讨厌且非常无用的错误)并且无法找到我的 VM 定位器。当我从 App.xaml 中删除该块时,它会立即起作用,但基于我对 WPF 的非常有限的了解,如果我希望这些样式可用于我的应用程序中的所有视图,我需要这些。
有什么想法吗?这已经让我发疯了几个小时了。
【问题讨论】:
标签: wpf mvvm-light resourcedictionary