2009-12-09 5 views
0

안녕하세요,에서 이동하는 방법 :실버 라이트 3 - 변경 병합 사전 동적으로

<Application 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
x:Class="teste.App"> 
<Application.Resources> 
    <!-- Resources scoped at the Application level should be defined here. --> 
    <ResourceDictionary> 
    <ResourceDictionary.MergedDictionaries> 
    **<ResourceDictionary Source="Green.xaml"/>** 
    </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 
</Application> 

사람 : 사용자가 테마를 선택하면이 이

<Application 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
x:Class="teste.App"> 
<Application.Resources> 
    <!-- Resources scoped at the Application level should be defined here. --> 
    <ResourceDictionary> 
    <ResourceDictionary.MergedDictionaries> 
    **<ResourceDictionary Source="Blue.xaml"/>** 
    </ResourceDictionary.MergedDictionaries> 
    </ResourceDictionary> 
</Application.Resources> 
</Application> 

동적으로 ... 그것을이다

가능한? 당신은 page.xaml의 부하에, 뒤에 코드에서 동적 리소스 사전을 변경할 수 있습니다 당신에게 Josi

답변

0

감사합니다

응용 프로그램 :

//Load in resources either from application 
     ResourceDictionary dictionary = Application.Current.Resources as ResourceDictionary; 
다음

당신은 자원을 일단 간단한 논리를 사용하여 사전에 적용 할 수 있습니다.

//Load in xaml 
     if (user1) 
      themefile = @"[Assembly];component/Themes/blue.xaml"; 
     else 
      themefile = @"[Assembly];component/Themes/green.xaml"; 

NB : [어셈블리]는 n xaml 파일이있는 구성 요소의 여백. 한 번 새 테마를 설정 전체 응용 프로그램에 적용 할 수있는 방법이 있나요

XDocument xaml = XDocument.Load(themefile); 
ResourceDictionary rd = XamlReader.Load(xaml.ToString()) as ResourceDictionary; 

     dictionary.MergedDictionaries.Add(rd); 
+0

:

다음과 페이지의 dictioanry에 병합? –

+0

XDocument는 어떤 네임 스페이스입니까? –

+0

XDocument는 System.Linq 네임 스페이스에 있습니다. –