Created
May 24, 2012 10:46
-
-
Save khmylov/2780791 to your computer and use it in GitHub Desktop.
Interactivity behavior for application bar with overriden theme (WP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OverlappingAppBarBehavior: Behavior<PhoneApplicationPage> | |
{ | |
private static readonly double _appBarOffset = 74.0; | |
private static readonly double _reducedAppBarOffset = 70.0; | |
private static readonly double _appBarOpacity = 0.99; | |
private static readonly IDictionary<PageOrientation, Thickness> _pageMargins = new Dictionary<PageOrientation, Thickness> | |
{ | |
{PageOrientation.PortraitUp, new Thickness(0.0, 0.0, 0.0, _appBarOffset)}, | |
{PageOrientation.PortraitDown, new Thickness(0.0, _appBarOffset, 0.0, 0.0)}, | |
{PageOrientation.LandscapeLeft, new Thickness(0.0, 0.0, _reducedAppBarOffset, 0.0)}, | |
{PageOrientation.LandscapeRight, new Thickness(_appBarOffset, 0.0, 0.0, 0.0)} | |
}; | |
protected override void OnAttached() | |
{ | |
AssociatedObject.Loaded += OnLoaded; | |
AssociatedObject.OrientationChanged += OnOrientationChanged; | |
} | |
private void OnLoaded(object sender, RoutedEventArgs e) | |
{ | |
AssociatedObject.Loaded -= OnLoaded; | |
UpdateAppBarState(); | |
} | |
private void OnOrientationChanged(object sender, OrientationChangedEventArgs e) | |
{ | |
UpdateAppBarState(); | |
} | |
private void UpdateAppBarState() | |
{ | |
var appBar = AssociatedObject.ApplicationBar; | |
if (appBar == null) | |
{ | |
return; | |
} | |
appBar.Opacity = _appBarOpacity; | |
var content = AssociatedObject.Content as FrameworkElement; | |
if (content == null) | |
{ | |
return; | |
} | |
Thickness margin; | |
AssociatedObject.Margin = _pageMargins.TryGetValue(AssociatedObject.Orientation, out margin) | |
? margin | |
: new Thickness(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment