Closed rmtuckerphx closed 11 years ago
You can do this using the OnLoaded event of the control. This is how I do it in my own app:
In XAML
<bindableAppBar:BindableAppBar IsVisible="True" Loaded="FrameworkElement_OnLoaded">
In code-behind
private void FrameworkElement_OnLoaded(object sender, RoutedEventArgs e) {
var appbar = sender as BindableAppBar;
// Light theme
appbar.MatchOverriddenTheme();
appbar.StateChanged += (o, args) => appbar.MatchOverriddenTheme();
appbar.Invalidated += (o, args) => appbar.MatchOverriddenTheme();
}
To promote reusability, feel free to inherit from my appbar class and add this code to the constructor.
public class ThemeableBindableAppBar : BindableAppBar {
public ThemeableBindableAppBar() {
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs e) {
// Light theme
this.MatchOverriddenTheme();
this.StateChanged += (o, args) => this.MatchOverriddenTheme();
this.Invalidated += (o, args) => this.MatchOverriddenTheme();
}
}
I want to use the ThemeManager (see http://www.jeff.wilcox.name/2012/01/phonethememanager/) to style the ApplicationBar.
How do I get access to the ApplicationBar so that I can call:
ThemeManager.MatchOverriddenTheme(appBar);