【问题标题】:ResourceDictionary with Caliburn MicroCaliburn Micro 的资源字典
【发布时间】:2014-03-06 09:08:24
【问题描述】:
app.xaml

<Application.Resources>
    <local:AppBootstrapper xmlns:local="clr-namespace:Kyms" x:Key="Bootstrapper" />
    <local:LocalizedStrings xmlns:local="clr-namespace:Kyms" x:Key="LocalizedStrings"/>
    <ResourceDictionary x:Key="CustomDictionary">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Styles/Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>

我在 Styles/Styles.xaml 中的资源

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


<Style x:Key="MyColorButton" TargetType="Button">
   .......
</Style>

如果我调用此代码,则在 ViewModel 中(使用 caliburn micro MVVM 模式)

App.Current.Resources.MergedDictionaries[0]

App.Current.Resources.MergedDictionaries.Count = 0

但它不起作用,为什么?

【问题讨论】:

    标签: windows-phone-8 caliburn.micro


    【解决方案1】:

    我解决了

    在我的 AppBootstrapper.cs 中插入

     private void LoadDictionary()
        {
            var dictionaries = App.Current.Resources.MergedDictionaries;
            dictionaries.Clear();
    
            var themeStyles = new ResourceDictionary { Source = new Uri("/MyAssemblyName;component/Styles/Styles.xaml", UriKind.RelativeOrAbsolute) };
            dictionaries.Add(themeStyles);
        }
    

    而且它有效!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-29
      • 2012-10-24
      • 2012-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多