【问题标题】:MergedDictionaries in XAML rewritten to codeXAML 中的 MergedDictionaries 重写为代码
【发布时间】:2013-07-26 14:57:34
【问题描述】:

App.xaml 中的此 XAML 代码:

<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

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

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 集合最初是空的。

【问题讨论】:

    标签: c# wpf xaml styles mergeddictionaries


    【解决方案1】:

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

    Ans2) 不,您不需要Clear() 他们,因为没有MergedDictionaries,因此Count0

    【讨论】:

    • 非常感谢您快速 - 几乎立即 - 回答。 :)
    猜你喜欢
    • 1970-01-01
    • 2011-04-19
    • 2011-01-03
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    相关资源
    最近更新 更多