I'm trying to set an option in a settings flyout in my WinRT app for the user to change the theme of the app.

In the App.xaml file, I've set up different ResourceDictionaries for the light and dark themes. I can set the desired theme of my application from it's settings file with the following code (`RootPage` is the name of the grid the contains all of the elements):

```
if ((string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["Theme"] == "0")
{
    RootPage.RequestedTheme = Windows.UI.Xaml.ElementTheme.Light;
}
if ((string)Windows.Storage.ApplicationData.Current.LocalSettings.Values["Theme"] == "1")
{
    RootPage.RequestedTheme = Windows.UI.Xaml.ElementTheme.Dark;
}

```

However, I would like to be able to change the theme dynamically. Basically, I want the theme to change immediately when the user selects the desired theme from the settings flyout, rather than having to wait for the application to be restarted.

I've tried using the following command:

```
App.Current.RequestedTheme = Windows.UI.Xaml.ApplicationTheme.Light;

```

But this crashes the app with a `System.NotSupportedException`.

I've also tried setting the theme only to the RootPage element with the following:

```
var MainPage = Windows.UI.Xaml.Window.Current.Content as MainPage;
MainPage.RootPage.RequestedTheme = Windows.UI.Xaml.ElementTheme.Light;

```

But I've done this wrong because it raises a `System.NullReferenceException`.

Could anyone help me work out how can I change the RequestedTheme of an element from a control in a settings flyout?