感謝Nikita Brizhak,我成功了。 這裏是完整的「如何」:
1)您需要添加一個OnStartUp方法App.xaml.cs.這裏是語法:
protected override void OnStartup(StartupEventArgs e)
2)您必須清除所有資源。
Application.Current.Resources.Clear();//This is if you have on your App.xaml a load of your resource. Clear it and than load another.
//It is good to have this so you can see you style while working on the project, But on runtime to replace.
Application.Current.Resources.MergedDictionaries.Clear();
3)你必須加載動態資源
終極密碼:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Application.Current.Resources.Clear();
Application.Current.Resources.MergedDictionaries.Clear();
StreamReader stream = new StreamReader("Styles.xaml");
Application.Current.Resources.MergedDictionaries.Add(System.Windows.Markup.XamlReader.Load(stream.BaseStream) as ResourceDictionary);
}
我相信你可以創建一個DLL與相應的資源字典,然後使用反射從組件拉這一點,將它們添加到您的Application.Current.Resources.MergedDictionaries。 – TYY