2012-02-15 3 views
1

전체 응용 프로그램의 사용자 지정 테마를 동적으로 변경하려고합니다. 테마는 ExpressionDark.xaml 및 ExpressionLight.xaml (Codeplex에서 다운로드)이라는 리소스 사전으로 제공됩니다. 콤보 상자를 사용하여 적절한 테마를 선택합니다. SelectionChanged 이벤트에서 테마 변경이 발생했습니다.WPF를 사용하여 전체 응용 프로그램에 다른 사용자 지정 테마 (리소스 사전)를 적용하는 방법은 무엇입니까?

private void themesComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
ResourceDictionary resourceDictionary = new ResourceDictionary(); 

    int theme = ((ComboBox)sender).SelectedIndex; 

    switch (theme) 
    { 
    case (int)Themes.Dark: 
       resourceDictionary = Application.LoadComponent(
       new Uri(@"Themes\ExpressionDark.xaml", 
       UriKind.Relative)) as ResourceDictionary; 
       break; 
      case (int)Themes.Light: 
       resourceDictionary = Application.LoadComponent(
       new Uri(@"Themes\ExpressionLight.xaml", 
       UriKind.Relative)) as ResourceDictionary; 
       break; 
      default: 
       break; 
    } 

Application.Current.Resources = resourceDictionary; 
} 

이 현재 창에 대한 잘 작동하지만 다른 응용 프로그램 윈도우의 인스턴스를 실행할 때 XamlParseException가 발생 여기에 코드입니다.

답변

2
ResourceDictionary skin = new ResourceDictionary(); 
skin.Source = new Uri("Themes\\ExpressionLight.xaml", UriKind.Relative); 
Application.Current.Resources.MergedDictionaries.Clear(); 
Application.Current.Resources.MergedDictionaries.Add(skin); 
+1

감사합니다. –

관련 문제