Skip to content

Commit

Permalink
Merge pull request #4054 from MahApps/fix/GH-4012
Browse files Browse the repository at this point in the history
Fix FlipView SelectionChanged event firing twice
  • Loading branch information
punker76 authored Feb 27, 2021
2 parents 4836329 + 5e17639 commit 04729f7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/MahApps.Metro/Controls/FlipView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace MahApps.Metro.Controls
[TemplatePart(Name = PART_DownButton, Type = typeof(Button))]
[TemplatePart(Name = PART_BannerGrid, Type = typeof(Grid))]
[TemplatePart(Name = PART_BannerLabel, Type = typeof(Label))]
[TemplatePart(Name = PART_Index, Type = typeof(ListBox))]
[StyleTypedProperty(Property = nameof(NavigationButtonStyle), StyleTargetType = typeof(Button))]
[StyleTypedProperty(Property = nameof(IndexItemContainerStyle), StyleTargetType = typeof(ListBoxItem))]
public class FlipView : Selector
Expand Down Expand Up @@ -696,6 +697,7 @@ public string ButtonDownContentStringFormat
private const string PART_ForwardButton = "PART_ForwardButton";
private const string PART_Presenter = "PART_Presenter";
private const string PART_UpButton = "PART_UpButton";
private const string PART_Index = "PART_Index";
/// <summary>
/// To counteract the double Loaded event issue.
/// </summary>
Expand Down Expand Up @@ -911,6 +913,20 @@ public override void OnApplyTemplate()
{
this.bannerLabel.Opacity = this.IsBannerEnabled ? 1d : 0d;
}

this.ExecuteWhenLoaded(() =>
{
if (this.GetTemplateChild(PART_Index) is ListBox listBox)
{
listBox.SelectionChanged += (sender, e) =>
{
if (ReferenceEquals(e.OriginalSource, listBox))
{
e.Handled = true;
}
};
}
});
}

protected override DependencyObject GetContainerForItemOverride()
Expand Down

0 comments on commit 04729f7

Please sign in to comment.