2014-08-31 3 views
1

내 WinRT 앱 사용자는 서버와 데이터를 동기화 할 수 있습니다. 동기화되는 일부 데이터는 애플리케이션의 글로벌 테마 변경 사항입니다.즉시 글로벌 테마 변경 적용

XAML 파일을 동적으로 생성 한 다음 글로벌 테마를 변경하려고합니다.

var resource = (ResourceDictionary)XamlReader.Load(content); 

그런 다음이 작업을 통해 앱의 글로벌 테마를 덮어 씁니다.

var resources = new ResourceDictionary(); 
var converters = new ResourceDictionary { Source = new Uri("ms-appx:/Resources/Converters.xaml") }; 
var callisto = new ResourceDictionary { Source = new Uri("ms-appx:/Resources/Callisto.xaml") }; 
var templates = new ResourceDictionary { Source = new Uri("ms-appx:/Resources/Templates.xaml") }; 

resources.MergedDictionaries.Add(converters); 
resources.MergedDictionaries.Add(callisto); 
resources.MergedDictionaries.Add(templates); 
resources.MergedDictionaries.Add(resource); 

App.Current.Resources = resources; 

리소스 파일에는이 파일이 있습니다.

<ImageBrush x:Key="ApplicationPageBackgroundThemeImageBrush" ImageSource="%%ThemeBackground%%" Stretch="UniformToFill" /> 

%%ThemeBackground%%은 실제 파일 위치로 대체됩니다.

변경 사항 중 일부는 NavigationBackButtonNormalStyle 스타일처럼 즉시 적용되지만 다른 변경 사항은 ImageBrush처럼 적용됩니다. 변경 사항은 앱이 다시 시작될 때만 표시되며 실행중인 페이지가 아닌 App.xaml.cs의 애플리케이션 실행 중에이 코드가 실행됩니다.

이게 가능합니까?

이 작동 방식에 대한 몇 가지 참고 사항.

  • 테마를 설정하는 코드는 별도의 클래스에 있으며 앱의 어디에서나 호출 할 수 있습니다.
  • ImageBrush이 (가) <Border Background="{ThemeResource ApplicationPageBackgroundThemeImageBrush}"></Border>에 적용됩니다.
  • 테마 변경 사항은 Style과 같은 일부 내용이 적용되어 NavigationBackButtonNormalStyle으로 변경됩니다.
  • Background 대신 Style 변경을 시도했지만 그 중 하나도 작동하지 않았습니다.

업데이트

나는이와 "마스터 페이지"설치의 종류가. 이것은 그것이 만들어지는 방법입니다.

var currentFrame = (Frame)Window.Current.Content; 
var masterPage = new MasterPage 
{ 
    ContentFrame = currentFrame, 
}; 
Window.Current.Content = masterPage; 

마스터 페이지에는 TopAppBar이 있습니다.

<Page.TopAppBar> 
    <!-- buttons here --> 
</Page.TopAppBar> 
<Grid> 
    <ContentControl Content="{Binding ContentFrame, ElementName=PageRoot}" /> 
</Grid> 

업데이트되지 않는 배경 이미지는 모든 페이지에 이와 같이 적용됩니다.

<Border Background="{ThemeResource ApplicationPageBackgroundThemeImageBrush}"></Border> 

답변

1

페이지를 새로 고침하기 만하면됩니다.

이 작업을 시도 할 수 있습니다 :

public bool Reload(object param = null) 
{ 
    Type type = this.Frame.CurrentSourcePageType; 
    if (this.Frame.BackStack.Any()) 
    { 
     type = this.Frame.BackStack.Last().SourcePageType; 
     param = this.Frame.BackStack.Last().Parameter; 
    } 
    try { return this.Frame.Navigate(type, param); } 
    finally { this.Frame.BackStack.Remove(this.Frame.BackStack.Last()); } 
} 

행운을 빕니다!

+0

새로 고침 작업을해야합니까? 이것은 나를 위해 작동하지 않습니다. 저는 일종의 "마스터 페이지"를하고 있습니다. 아마도 그게 문제의 원인이 될 수 있습니다. 마스터 페이지를 어떻게 작성하고 있는지에 대한 질문에 더 자세히 설명합니다. –

+0

마스터 페이지를 제거했지만 여전히 작동하지 않았습니다. 앱을 닫고 다시 시작해야 배경 이미지가 변경됩니다. –