, . , . . Application.Resources, , .
Application.Resources - ResourceDictionary ResourceDictionary DependencyObject, Application.Resources DependencyObject.
DependencyObject , Window . , :
- , API DependencyObject, , . .
- , , DependencyObject, DependencyObject . , , . , , .NET ThreadPool, t API.
. DependencyObject threading DependencyObject.
, Window Application.Resources. Application.Resources ResourceDictionary. BackgroundBrush ,
(Application.Current.Resources["BackgroundBrush"] as SolidColorBrush).Color = Windows.UI.Colors.Black;
Application.Current.Resources, Window.
, , , , , . , BackgroundBrushColor App, , :
private void ThemeChanger_Click(object sender, RoutedEventArgs e)
{
App.BackgroundBrushColor = Windows.UI.Color.FromArgb(Convert.ToByte(random.Next(255)), Convert.ToByte(random.Next(255)), Convert.ToByte(random.Next(255)), Convert.ToByte(random.Next(255)));
(Application.Current.Resources["BackgroundBrush"] as SolidColorBrush).Color = App.BackgroundBrushColor;
}
private async Task CreateNewViewAsync()
{
CoreApplicationView newView = CoreApplication.CreateNewView();
int newViewId = 0;
await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
(Application.Current.Resources["BackgroundBrush"] as SolidColorBrush).Color = App.BackgroundBrushColor;
Frame frame = new Frame();
frame.Navigate(typeof(SecondaryPage), null);
Window.Current.Content = frame;
Window.Current.Activate();
newViewId = ApplicationView.GetForCurrentView().Id;
});
bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
}
, . ThemeChanged SecondaryPage.xaml.cs , , . .
, ThemeChanged , , ThemeManager_ThemeChanged, SecondaryPage.xaml.cs, , Application.Current.Resources in ThemeManager_ThemeChanged, - ResourceDictionary, . . , "" .
, this.Dispatcher.RunAsync , :
private async void ThemeManager_ThemeChanged(Utils.ThemeManager theme)
{
await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
((SolidColorBrush)Application.Current.Resources["BackgroundBrush"]).Color = theme.HighAccentColorBrush.Color;
});
}
, : " , ." , SolidColorBrush DependencyObject. , HighAccentColorBrush SolidColorBrush Color, :
private async void ThemeManager_ThemeChanged(Utils.ThemeManager theme)
{
await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
((SolidColorBrush)Application.Current.Resources["BackgroundBrush"]).Color = theme.HighAccentColorBrush;
});
}