From e8bc04b3467fe3f0dde8e06c2a3eb53bac7c782a Mon Sep 17 00:00:00 2001 From: Amrykid Date: Tue, 28 May 2013 18:05:56 -0500 Subject: [PATCH 1/2] Fixed a binding issue because of a bad setter. --- MahApps.Metro/Controls/FlipView.cs | 43 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/MahApps.Metro/Controls/FlipView.cs b/MahApps.Metro/Controls/FlipView.cs index 8c4734137d..193c9021d2 100644 --- a/MahApps.Metro/Controls/FlipView.cs +++ b/MahApps.Metro/Controls/FlipView.cs @@ -237,11 +237,10 @@ private void HideBanner() } public static readonly DependencyProperty BannerTextProperty = - DependencyProperty.Register("BannerText", typeof(string), typeof(FlipView), new PropertyMetadata("Banner", new PropertyChangedCallback((d, e) => + DependencyProperty.Register("BannerText", typeof(string), typeof(FlipView), new FrameworkPropertyMetadata("Banner", FrameworkPropertyMetadataOptions.AffectsRender ,new PropertyChangedCallback((d, e) => { - if (e.OldValue != e.NewValue) - ExecuteWhenLoaded(((FlipView)d), () => - ((FlipView)d).ChangeBannerText()); + ExecuteWhenLoaded(((FlipView)d), () => + ((FlipView)d).ChangeBannerText((string)e.NewValue)); }))); public string BannerText @@ -249,13 +248,7 @@ public string BannerText get { return (string)GetValue(BannerTextProperty); } set { - ExecuteWhenLoaded(this, () => - { - if (IsBannerEnabled) - ChangeBannerText(value); - else - SetValue(BannerTextProperty, value); - }); + SetValue(BannerTextProperty, value); } } @@ -266,20 +259,26 @@ private void ChangeBannerText(string value = null) { var newValue = value != null ? value : BannerText; - if (newValue == (string)GetValue(BannerTextProperty)) return; + //if (newValue == (string)GetValue(BannerTextProperty)) return; + + if (newValue == null) return; if (HideControlStoryboard_CompletedHandler != null) HideControlStoryboard.Completed -= HideControlStoryboard_CompletedHandler; HideControlStoryboard_CompletedHandler = new EventHandler((sender, e) => { - SetValue(BannerTextProperty, newValue); - - HideControlStoryboard.Completed -= HideControlStoryboard_CompletedHandler; + try + { + HideControlStoryboard.Completed -= HideControlStoryboard_CompletedHandler; - bannerLabel.Content = value != null ? value : BannerText; + bannerLabel.Content = newValue; - bannerLabel.BeginStoryboard(ShowControlStoryboard, HandoffBehavior.SnapshotAndReplace); + bannerLabel.BeginStoryboard(ShowControlStoryboard, HandoffBehavior.SnapshotAndReplace); + } + catch (Exception) + { + } }); @@ -339,14 +338,20 @@ public bool IsBannerEnabled private static void ExecuteWhenLoaded(FlipView flipview, Action body) { if (flipview.IsLoaded) - body(); + System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(new EmptyDelegate(() => + { + body(); + })); else { RoutedEventHandler handler = null; handler = new RoutedEventHandler((o, a) => { flipview.Loaded -= handler; - body(); + System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(new EmptyDelegate(() => + { + body(); + })); }); flipview.Loaded += handler; From 629063db3ec9f546486a4ee0fc95d95c6243127f Mon Sep 17 00:00:00 2001 From: Amrykid Date: Tue, 28 May 2013 19:32:46 -0500 Subject: [PATCH 2/2] Removed some whitespace. --- MahApps.Metro/Controls/FlipView.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/MahApps.Metro/Controls/FlipView.cs b/MahApps.Metro/Controls/FlipView.cs index 193c9021d2..2fadba6bcd 100644 --- a/MahApps.Metro/Controls/FlipView.cs +++ b/MahApps.Metro/Controls/FlipView.cs @@ -246,11 +246,7 @@ private void HideBanner() public string BannerText { get { return (string)GetValue(BannerTextProperty); } - set - { - SetValue(BannerTextProperty, value); - - } + set { SetValue(BannerTextProperty, value); } } private void ChangeBannerText(string value = null) @@ -259,8 +255,6 @@ private void ChangeBannerText(string value = null) { var newValue = value != null ? value : BannerText; - //if (newValue == (string)GetValue(BannerTextProperty)) return; - if (newValue == null) return; if (HideControlStoryboard_CompletedHandler != null)