Skip to content

Commit

Permalink
Merge pull request #492 from Amrykid/flipview-patch-2
Browse files Browse the repository at this point in the history
FlipView Patch #2
  • Loading branch information
AzureKitsune committed May 29, 2013
2 parents 125bdc7 + 629063d commit 7a56436
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions MahApps.Metro/Controls/FlipView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,27 +237,16 @@ 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
{
get { return (string)GetValue(BannerTextProperty); }
set
{
ExecuteWhenLoaded(this, () =>
{
if (IsBannerEnabled)
ChangeBannerText(value);
else
SetValue(BannerTextProperty, value);
});

}
set { SetValue(BannerTextProperty, value); }
}

private void ChangeBannerText(string value = null)
Expand All @@ -266,20 +255,24 @@ 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)
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)
{
}
});


Expand Down Expand Up @@ -339,14 +332,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;
Expand Down

0 comments on commit 7a56436

Please sign in to comment.