简体   繁体   English

WPF将第三方ResourceDictionary添加到App.xaml?

[英]WPF adding a third party ResourceDictionary to App.xaml?

This may well be a stupid question, but I cannot find an answer... 这可能是一个愚蠢的问题,但我找不到答案。

I am just getting started with WPF, and am trying to add a ResourceDictionary to my project. 我刚刚开始使用WPF,并且正在尝试向我的项目添加ResourceDictionary。

this one here: 这一个在这里:

https://monotone.codeplex.com/ https://monotone.codeplex.com/

So I downloaded the zip file, and unzipped it to: 因此,我下载了zip文件,并将其解压缩为:

MyProjectDir/MonoTone

I have added the following to my App.xaml 我已将以下内容添加到我的App.xaml

 <Application x:Class="TestWPF.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:TestWPF"
             xmlns:xcad="http://schemas.xceed.com/wpf/xaml/avalondock"
             StartupUri="MainWindow.xaml">

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                <ResourceDictionary Source="Monotone/Monotone.Colors.xaml" />
                <ResourceDictionary Source="Monotone/Monotone.Brushes.xaml" />
                <ResourceDictionary Source="Monotone/Monotone.MahApps.xaml" />
                <ResourceDictionary Source="Monotone/Monotone.xaml" />
                <ResourceDictionary Source="Monotone/Monotone.ExtendedWPFToolkit.xaml" />
                <ResourceDictionary Source="Monotone/Monotone.ColorBox.xaml" />

            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

    </Application.Resources>

</Application>

as here: 如这里:

https://monotone.codeplex.com/wikipage?title=Installing%20Monotone&referringTitle=Documentation https://monotone.codeplex.com/wikipage?title=Installing%20Monotone&referringTitle=Documentation

Now Intelsense is underlining the xaml paths, and cannot find the files. 现在,Intelsense正在突出显示xaml路径,并且找不到文件。

I have added a reference to the dll. 我已经添加了对dll的引用。 What am i missing? 我想念什么?

Thank you. 谢谢。

First, try including the Monotone catalog in the solution by clicking on show all files icon in solution explorer. 首先,通过在解决方案资源管理器中单击“显示所有文件”图标,尝试将Monotone目录包括在解决方案中。

Second, as shown in below screen, pinpoint the exact path as in the first line of example. 其次,如下面的屏幕所示,按照示例的第一行精确定位路径。 例

To explicitly answer your question: Visual Studio was complaining because you needed to add the Monotone files (from the release zip) to your project under a folder called "Monotone". 明确回答您的问题:Visual Studio在抱怨,因为您需要将Monotone文件(来自发行版zip)添加到项目中名为“ Monotone”的文件夹下。 Janis S's answer already stated this. Janis S的答案已经说明了这一点。

Unfortunately, the Monotone project contains a few dependencies on other projects... Specifically, you'll notice that it references the ColorBox control, which can be found on CodePlex , and it also depends on some Xceed assemblies. 不幸的是,Monotone项目包含对其他项目的一些依赖...特别是,您会注意到它引用了ColorBox控件,该控件可以在CodePlex上找到,并且还依赖于某些Xceed程序集。 Your project will not build without those. 没有这些内容,您的项目将无法构建。

A few examples of the references to external dependencies are: 引用外部依赖项的一些示例是:

xmlns:xtk="http://schemas.xceed.com/wpf/xaml/toolkit"
xmlns:nc="http://schemas.ncore.com/wpf/xaml/colorbox"
xmlns:conv="clr-namespace:Xceed.Wpf.Toolkit.Converters;assembly=Xceed.Wpf.Toolkit"
xmlns:Behaviours="clr-namespace:MahApps.Metro.Behaviours"
xmlns:mm="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:mmm="http://metro.mahapps.com/winfx/xaml/shared"

At this point you have three options 此时,您有三个选择

  1. remove all references to the external assemblies. 删除所有对外部程序集的引用。
  2. OR figure out which assemblies are needed and add references to those as well. 或找出需要哪些程序集,并同时添加对这些程序集的引用。
  3. OR find a different dark theme to use. 或找到要使用的其他深色主题。

Option 3 is probably the best one at this point as CodePlex is shutting down soon and Monotone does not appear to be maintained. 由于CodePlex即将关闭并且Monotone似乎没有得到维护,因此选项3在此时可能是最好的选择。 A quick Google search results in a few free WPF Dark Themes that are still functioning that could be used instead. 快速的Google搜索会产生一些免费的WPF黑暗主题,这些主题仍然可以使用。

Edit 编辑

If you really want to use Monotone, go to their downloads page and grab the sample application. 如果您真的想使用Monotone,请转到他们的下载页面并获取示例应用程序。 All of the missing DLLs are included in that download (you will need to include those in your project and add them as references ). 所有缺少的DLL都包含在该下载中(您将需要在项目中包含这些DLL, 并将其添加为引用 )。

I might be very late to the party, but to clarify things: 我参加聚会可能很晚,但要澄清一下:

  • I am the creator of Monotone (which was a theme I used for an IDE I developed which is now obsolete). 我是Monotone的创建者(Monotone(这是我用于已淘汰的IDE所使用的主题)。 I don't mind if you pick another/better dark theme for your application, it's pretty old at this point. 我不介意您为应用程序选择另一个/更好的深色主题,在这一点上它已经很老了。

  • Monotone is now 'maintained' on GitHub. Monotone现在“维护”在GitHub上。 Well, it's more or less stale at this point since I'm not into C# anymore. 好吧,由于我不再使用C#,这时或多或少有些陈旧。 But if you (or anyone else) have a specific problem with it, feel free to submit an issue on GitHub or a pull request that solves it. 但是,如果您(或其他任何人)对此有特定的问题,请随时在GitHub上提交问题或解决该问题的请求请求。

  • You only need to add the XAML-files for Monotone.Colors.xaml , Monotone.Brushes.xaml and Monotone.xaml to the ResourceDictionary.MergedDictionaries for the default WPF controls. 您只需为默认WPF控件将Monotone.Colors.xamlMonotone.Brushes.xamlMonotone.xaml的XAML文件添加到ResourceDictionary.MergedDictionaries Include in this order. 按此顺序包括。 If I remember correctly the files have to be set to EmbeddedResource . 如果我没记错的话,必须将文件设置为EmbeddedResource That's it. 而已。

  • Monotone.ExtendedWPFToolkit.xaml is only needed if you use (and want to theme) the ExtendedWPFToolkit controls. 仅当您使用(并希望为其设置主题)ExtendedWPFToolkit控件时,才需要Monotone.ExtendedWPFToolkit.xaml Sames goes for Monotone.MahApps.xaml and Monotone.ColorBox.xaml . Monotone.MahApps.xamlMonotone.ColorBox.xaml So, these are optional. 因此,这些是可选的。 It's kept in separate files to avoid dependencies to libaries you might not use 它保存在单独的文件中,以避免依赖于您可能不使用的库

  • You don't need the DLLs for styling the standard WPF controls 您不需要使用DLL来设置标准WPF控件的样式

  • Because of the shutdown of CodePlex the Wiki-Pages are gone. 由于CodePlex的关闭,Wiki页消失了。 I might dig into the code and recreate it on GitHub (or even better add it to the repo itself), that you have a helpful documentation. 我可能会深入研究代码,然后在GitHub上重新创建代码(甚至最好将其添加到存储库本身中),以获取有用的文档。

  • As pointed out, the SampleApplication contains a working example which you can use as a template and/or to understand how it works 如前所述,SampleApplication包含一个工作示例,您可以将其用作模板和/或了解其工作方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM