English 中文(简体)
MVVM Light ViewModelLocator+资源字典
原标题:MVVM Light ViewModelLocator + ResourceDictionaries

我最初在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的有限了解,如果我想让样式对应用程序中的所有视图都可用,我需要这些样式。

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

最佳回答

是的。。。我前几天刚刚看到这个。。。你必须在里面放一本资源字典。。。

    <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>

**EDIT Sorry...Fixed it now...I was going from memory...this is the way it is in mine.

<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>
问题回答

暂无回答




相关问题
WPF convert 2d mouse click into 3d space

I have several geometry meshes in my Viewport3D, these have bounds of (w:1800, h:500, d:25). When a user clicks in the middle of the mesh, I want the Point3D of (900, 500, 25)... How can I achieve ...

Editing a xaml icons or images

Is it possible to edit a xaml icons or images in the expression design or using other tools? Is it possible to import a xaml images (that e.g you have exported) in the expression designer for editing?...

WPF: writing smoke tests using ViewModels

I am considering to write smoke tests for our WPF application. The question that I am faced is: should we use UI automation( or some other technology that creates a UI script), or is it good enough to ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

How do WPF Markup Extensions raise compile errors?

Certain markup extensions raise compile errors. For example StaticExtension (x:Static) raises a compile error if the referenced class cannot be found. Anyone know the mechanism for this? Is it baked ...

WPF design-time context menu

I am trying to create a custom wpf control, I m wondering how I can add some design-time features. I ve googled and can t seem to get to my goal. So here s my simple question, how can I add an entry ...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签