来自绑定的 wpf 资源字典源



在我的app.xaml中,我有很多样式可以加载,这就是那个列表

    <Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Themes/dark.xaml"/>
            <ResourceDictionary Source="Themes/Orange.xaml"/>
            <ResourceDictionary Source="Controls/Button.xaml"/>
            <ResourceDictionary Source="Controls/CheckBox.xaml"/>
            <ResourceDictionary Source="Controls/Controls.xaml"/>
            <ResourceDictionary Source="Controls/ContextMenu.xaml"/>
            <ResourceDictionary Source="Controls/ScrollBar.xaml"/>
            <ResourceDictionary Source="Controls/ScrollViewer.xaml"/>
......
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

现在我需要在运行时将拖曳冷杉源 URL 更改为属性中的值.设置.默认值我不知道我该怎么办我搜索这个,但没有什么找不到理解

var newsource1= new Uri("pack://siteoforigin:,,,/resources/xxxx.xaml", UriKind.RelativeOrAbsolute);
var newsource2= new Uri("pack://siteoforigin:,,,/resources/yyyyy.xaml", UriKind.RelativeOrAbsolute);
Application.Current.Resources.MergedDictionaries.Remove(Appl‌​ication.Current.Reso‌​urces.MergedDictiona‌​ries[0]);
Application.Current.Resources.MergedDictionaries.Remove(Appl‌​ication.Current.Reso‌​urces.MergedDictiona‌​ries[1]);
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = newsource1});
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = newsource2});

由于没有可用于编辑资源字典运行时的功能。实现预期目标的可能解决方案是删除并添加资源字典运行时。

真诚地

蒂亚古·拉金德兰

**如果有帮助,请将回复标记为答案。

最新更新