XAML中的MergedDictionaries已被改写为代码。

6

这是在 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)
        });
    }
}
< p>< br/>< br/> < em>顺便提一下:在这种情况下,我需要在开始添加合并的字典之前调用Application.Current.Resources.MergedDictionaries.Clear()吗?我认为此时默认的MergedDictionaries集合最初是空的。

1个回答

4

答案1) 是的,完全相同。

答案2) 不需要清除它们,因为没有“合并字典”,因此“Count”为“0”。


非常感谢您的快速回复 - 几乎是立即的 - :) - kajovajo

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