Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FlipView SelectionChanged event firing twice #4054

Merged
merged 1 commit into from
Feb 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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