Changing App Skin at Runtime RRS feed

  • Question

  • Is 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?
    Wednesday, July 18, 2012 7:34 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");	
    		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 Jiang Thursday, July 19, 2012 8:18 AM
    • Marked as answer by peterGro Thursday, July 19, 2012 8:21 AM
    Wednesday, July 18, 2012 8:06 AM

All replies