// Source - https://stackoverflow.com/a/79833153
// Posted by EldHasp
// Retrieved 2025-11-29, License - CC BY-SA 4.0
using System.Windows;
using System.Windows.Input;
namespace SOQuestions2025.Questions.AdamWritesCode.question79831972
{
public static class UIElementHelper
{
public static bool GetIsBubbleLeftClick(UIElement obj)
{
return (bool)obj.GetValue(IsBubbleLeftClickProperty);
}
public static void SetIsBubbleLeftClick(UIElement obj, bool value)
{
obj.SetValue(IsBubbleLeftClickProperty, value);
}
// Using a DependencyProperty as the backing store for IsBubbleLeftClick. This enables animation, styling, binding, etc...
public static readonly DependencyProperty IsBubbleLeftClickProperty =
DependencyProperty.RegisterAttached(nameof(IsBubbleLeftClickProperty)[0..^8],
typeof(bool),
typeof(UIElementHelper),
new PropertyMetadata(true)
{
PropertyChangedCallback = OnIsBubbleLeftClickChanged
});
private static void OnIsBubbleLeftClickChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
UIElement uie = (UIElement)d;
uie.RemoveHandler(UIElement.MouseLeftButtonDownEvent, (MouseButtonEventHandler)HandledEvent);
if (false.Equals(e.NewValue))
{
uie.AddHandler(UIElement.MouseLeftButtonDownEvent, (MouseButtonEventHandler)HandledEvent, true);
}
}
private static void HandledEvent(object sender, RoutedEventArgs e)
{
e.Handled = true;
}
}
}