Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7957211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:12:54+00:00 2026-06-04T04:12:54+00:00

Why IsMouseOver is recognized as a WPF style trigger and MouseDown isn’t -given that

  • 0

Why IsMouseOver is recognized as a WPF style trigger and MouseDown isn’t -given that both are valid UIElement properties as seen here-. First trigger works well but second one doesn’t even compile.

<Style.Triggers>
    <Trigger Property="IsMouseOver" Value="true">
        <Setter Property="OpacityMask">
            <Setter.Value>
                <LinearGradientBrush >
                    <GradientStop Color="Transparent" Offset="0"/>
                    <GradientStop Color="Black" Offset="0.5"/>
                    <GradientStop Color="Transparent" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
    </Trigger>
    <Trigger Property="MouseDown" Value="true">
        <Setter Property="OpacityMask">
            <Setter.Value>
                <LinearGradientBrush>
                    <GradientStop Color="Black" Offset="0" />
                    <GradientStop Color="White" Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
    </Trigger>
</Style.Triggers>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:12:55+00:00Added an answer on June 4, 2026 at 4:12 am

    Well, I guess you are mistaking MouseDown event for property. There is no IsMouseDown property but there exist similar IsPressed property but only for classes inheriting ButtonBase. You should just use event in code-behind or write an attached property if you want to keep your code-behind clean.

    This is how you do it. Create class:

    using System;
    using System.Windows;
    
    namespace Mrpyo
    {
        public static class MouseDownHelper 
        {
            public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.RegisterAttached("IsEnabled", 
            typeof(bool), typeof(MouseDownHelper), new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnNotifyPropertyChanged)));
    
            public static void SetIsEnabled(UIElement element, bool value)
            {
                element.SetValue(IsEnabledProperty, value);
            }
    
            public static bool GetIsEnabled(UIElement element)
            {
                return (bool)element.GetValue(IsEnabledProperty);
            }
    
            private static void OnNotifyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                var element = d as UIElement;
                if (element != null && e.NewValue != null)
                {
                    if ((bool)e.NewValue)
                    {
                        Register(element);
                    }
                    else
                    {
                        UnRegister(element);
                    }
                } 
            }
    
            private static void Register(UIElement element)
            {
                element.PreviewMouseDown += element_MouseDown;
                element.PreviewMouseLeftButtonDown += element_MouseLeftButtonDown;
                element.MouseLeave += element_MouseLeave;
                element.PreviewMouseUp += element_MouseUp;
            }
    
            private static void UnRegister(UIElement element)
            {
                element.PreviewMouseDown -= element_MouseDown;
                element.PreviewMouseLeftButtonDown -= element_MouseLeftButtonDown;
                element.MouseLeave -= element_MouseLeave;
                element.PreviewMouseUp -= element_MouseUp;
            }
    
            private static void element_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                var element = sender as UIElement;
                if (element != null)
                {
                    SetIsMouseDown(element, true);
                }
            }
    
            private static void element_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                var element = sender as UIElement;
                if (element != null)
                {
                    SetIsMouseLeftButtonDown(element, true);
                }
            }
    
            private static void element_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
            {
                var element = sender as UIElement;
                if (element != null)
                {
                    SetIsMouseDown(element, false);
                    SetIsMouseLeftButtonDown(element, false);
                }
            }
    
            private static void element_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
            {
                var element = sender as UIElement;
                if (element != null)
                {
                    SetIsMouseDown(element, false);
                    SetIsMouseLeftButtonDown(element, false);
                }
            }
    
            internal static readonly DependencyPropertyKey IsMouseDownPropertyKey = DependencyProperty.RegisterAttachedReadOnly("IsMouseDown",
            typeof(bool), typeof(MouseDownHelper), new FrameworkPropertyMetadata(false));
            public static readonly DependencyProperty IsMouseDownProperty = IsMouseDownPropertyKey.DependencyProperty;
    
            internal static void SetIsMouseDown(UIElement element, bool value)
            {
                element.SetValue(IsMouseDownPropertyKey, value);
            }
    
            public static bool GetIsMouseDown(UIElement element)
            {
                return (bool)element.GetValue(IsMouseDownProperty);
            }
    
            internal static readonly DependencyPropertyKey IsMouseLeftButtonDownPropertyKey = DependencyProperty.RegisterAttachedReadOnly("IsMouseLeftButtonDown",
            typeof(bool), typeof(MouseDownHelper), new FrameworkPropertyMetadata(false));
            public static readonly DependencyProperty IsMouseLeftButtonDownProperty = IsMouseLeftButtonDownPropertyKey.DependencyProperty;
    
            internal static void SetIsMouseLeftButtonDown(UIElement element, bool value)
            {
                element.SetValue(IsMouseLeftButtonDownPropertyKey, value);
            }
    
            public static bool GetIsMouseLeftButtonDown(UIElement element)
            {
                return (bool)element.GetValue(IsMouseLeftButtonDownProperty);
            }
        }
    }
    

    Then in your style:

    <Setter Property="local:MouseDownHelper.IsEnabled" Value="True"/>
    <Style.Triggers>
        <Trigger Property="local:MouseDownHelper.IsMouseLeftButtonDown" Value="True">
            <!-- ... -->
        </Trigger>
    </Style.Triggers>
    

    And of course add namespace in your XAML file (look at the top):

    xmlns:local="clr-namespace:Mrpyo"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I try to change image for WPF trigger 'IsMouseOver' for button, the control
I have a WPF app with a Rectangle trigger defined as: <Style TargetType={x:Type Rectangle}>
I have a style with a Trigger for IsMouseOver , and I want to
I have the following xaml: <DockPanel> <DockPanel.Resources> <Style TargetType=Button> <Style.Triggers> <Trigger Property=IsMouseOver Value=True> <Setter
I created a simple, stripped ListView style that highlights an element when the IsMouseOver
The WPF Grid has an IsMouseOver property that you can use in the Grid's
I have WPF ContextMenu with MenuItems that support custom style. MenuItem is a ToggleButton.
<Image Source=Data\Images\close_nohover.bmp> <Image.Style> <Style TargetType={x:Type Image}> <Style.Triggers> <Trigger Property=IsMouseOver Value=True> <Setter Property=Source Value=Data\Images\close_hover.bmp />
Is there any order of execution for the trigger inside a controlTemplate of Style?.
I want to change cursor style when mouse is over the WPF TextBlock. <Style

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.