首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将XAML中的MergedDictionaries重写为代码

将XAML中的MergedDictionaries重写为代码
EN

Stack Overflow用户
提问于 2013-07-26 14:57:34
回答 1查看 3.7K关注 0票数 6

这是App.xaml中的XAML代码吗?

代码语言:javascript
复制
<Application x:Class="Company.Product.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >
    <Application.Resources>
      <ResourceDictionary>
          <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/System.Windows.xaml"/>
            <ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.xaml"/>
            <ResourceDictionary Source="/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.Data.xaml"/>               
          </ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </Application.Resources>
</Application>

相当于:

App.xaml

代码语言:javascript
复制
<Application x:Class="Company.Product.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    >
</Application>

App.xaml.cs

代码语言:javascript
复制
public partial class App : Application
{
    public App()
    {               
        Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
        {
            Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/System.Windows.xaml", UriKind.RelativeOrAbsolute)
        });
        Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
        {
            Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.xaml", UriKind.RelativeOrAbsolute)
        });
        Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary()
        {
            Source = new Uri("/Company.Windows.Themes.Theme1;component/Themes/Company.Windows.Controls.Data.xaml", UriKind.RelativeOrAbsolute)
        });
    }
}

请注意:在这种情况下,在开始添加合并字典之前,是否需要调用Application.Current.Resources.MergedDictionaries.Clear();?我认为现在默认的MergedDictionaries集合最初是空的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-26 15:02:28

Ans1)是的绝对的。他们是一样的。

Ans2)不,您不需要Clear(),因为没有MergedDictionaries,因此Count就是0

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

https://stackoverflow.com/questions/17884724

复制
相关文章

相似问题

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