如何在WPF中添加主题

3

错误 我想在WPF上添加ExpressionDark主题。

在App.xaml中:

<Application x:Class="ThemesSample.App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    StartupUri="MYWINDOW.xaml"> 
    <Application.Resources> 
        <ResourceDictionary Source="ExpressionDark.xaml"/> 
    </Application.Resources> 
</Application> 

在 MainWindow.cs 中:

public MainWindow()
{ 
    ResourceDictionary skin = new ResourceDictionary(); 
    skin.Source = new Uri(@"MYPROJECTADDR\ExpressionDark.xaml", UriKind.Absolute); 
    App.Current.Resources.MergedDictionaries.Add(skin); 
}

我在项目中添加了expressiondark.xaml文件,但是xpressiondark.xaml文件中的所有xmlns行都出现了错误。
有什么问题吗?

1
你是否将ExpressionDark.xaml添加到项目中了? - Blachshma
请向我们展示您收到的错误... - Blachshma
http://imageshack.us/photo/my-images/43/hata1uy.jpg/ - osunwa
由于某种奇怪的原因,我无法在imageshack中看到图片。您能否在原始问题中添加屏幕截图? - Blachshma
好的。我已经添加了。你认为有什么问题吗? - osunwa
2个回答

3

查看你的ExpressionDark.xaml的截图,ResourceDictionary部分包含了很多xmlns标签,而我的版本的ExpressionDark.xaml没有这些标签,我的版本只包含:

<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  mc:Ignorable="d"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008">

你的 ExpressionDark.xaml 文件是从哪里得到的?

试试这个链接:http://wpf.codeplex.com/downloads/get/62512


谢谢,我明白了并且在public MainWindow(){}中更正了dark.xaml地址。问题已经解决。 - osunwa

2
您可以尝试使用NuGet安装主题。从VS中,转到工具> NuGet包管理器>包管理器控制台,并输入以下命令以安装主题 PM> Install-Package WPF.Themes 这将在您的项目中创建一个名为Themes的目录并下载所有主题。它还会将ResourceDirectory添加到您的App.xaml中,您可以在其中选择所需的主题。 现在,您只需要拖放工具,运行应用程序时就会看到主题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接