首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MVVM轻量级ViewModelLocator + ResourceDictionaries

MVVM轻量级ViewModelLocator + ResourceDictionaries
EN

Stack Overflow用户
提问于 2011-05-28 02:14:18
回答 1查看 5.9K关注 0票数 7

我最初在MVVM Light CodePlex页面上发布了这条消息,但还没有听到回应,所以我希望这里的人能帮助我。下面是问题:

我最近开始使用MVVM (也是WPF的新手--所有这些学习起来都很费劲),在我开始使用CodePlex上提供的MetroToolkit之前,我的ViewModelLocator实例和VS2010的绑定设计时间都运行得很好。在使用这个工具包之前,我有以下几点:

代码语言:javascript
复制
<Application.Resources>
    <local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
</Application.Resources>

我所有的观点都很有约束力,一切看起来都很好。我惊讶于没有MVVM (或MVC)经验的人可以如此容易地启动和运行。然后我遇到了一个需要合并资源字典的MetroToolkit问题,现在无论我怎么尝试,我都不能让VS在App.xaml中再次找到我的ViewModelLocator。下面是新的标记:

代码语言:javascript
复制
<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非常有限的知识,如果我想让我的应用程序中的所有视图都可以使用这些样式,我需要这些样式。

有什么想法吗?这已经让我抓狂好几个小时了。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-28 09:15:57

是的.我刚刚看到另一个day...You必须在里面放一个资源字典...

代码语言:javascript
复制
    <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>
                     <local:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
                </ResourceDictionary>
                </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>

**现在编辑Sorry...Fixed它...我从memory...this开始就是我的方式。

代码语言:javascript
复制
<ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Dictionaries/converters.xaml" />
                <ResourceDictionary Source="assets/styles.xaml" />
                <ResourceDictionary Source="assets/sdkstyles.xaml" />
                <ResourceDictionary Source="assets/corestyles.xaml" />
                <ResourceDictionary>
                    <local:ApplicationResources x:Key="ApplicationResources" />
                </ResourceDictionary>

            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6156154

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档