Changing App Skin at Runtime
-
Wednesday, July 18, 2012 7:34 AMIs it possible to change the skin of a Metro app at runtime? I tried to write two resource dictionaries, put one into App.xaml and tried to load the second one later (after a button click) to "replace" the first one. But I didn't get it to work. Is it the right approach anyway or is it possible in any way to let the user choose between different skins for an app anyway?
All Replies
-
Wednesday, July 18, 2012 8:06 AM
I get it to work. Is this way ok?
void SkinChange::MainPage::btn_changeStyle_Click_1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { ResourceDictionary^ dict = ref new ResourceDictionary(); String^ old = App::Current->Resources->MergedDictionaries->GetAt(1)->Source->AbsoluteUri; std::wstring string = old->Data(); if (string.find(L"MyDict1.xaml") == -1) { dict->Source = ref new Uri("ms-resource:/Files/MyDict1.xaml"); } else { dict->Source = ref new Uri("ms-resource:/Files/MyDict2.xaml"); } App::Current->Resources->MergedDictionaries->SetAt(1, dict); App::LoadComponent(this, ref new Uri("ms-appx:///MainPage.xaml"), ComponentResourceLocation::Application); }
- Proposed As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Thursday, July 19, 2012 8:18 AM
- Marked As Answer by peterGro Thursday, July 19, 2012 8:21 AM
-
Thursday, July 19, 2012 8:18 AMModerator
Yes, Resource Dictionary is a solution. For more information, you can check these documents.
http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.resourcedictionaryResourceDictionary and StaticResource references (Metro style apps using C#/VB/C++ and XAML)
http://msdn.microsoft.com/en-us/library/windows/apps/hh968442http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh965329
Best regards,
JesseJesse Jiang [MSFT]
MSDN Community Support | Feedback to us


