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 8063613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:06:05+00:00 2026-06-05T11:06:05+00:00

I like the functionality of IsMouseDirectlyOverChanged, but it only works for the topmost elements.

  • 0

I like the functionality of IsMouseDirectlyOverChanged, but it only works for the topmost elements. What I really want to do is monitor the IsMouseOver property of a control, regardless of its z-index, and receive notification when IsMouseOver is modified. If I owned this property, I could do INotifyPropertyChanged, but unfortunately it’s owned by UIElement. Still learning the ropes of WPF, so maybe this is easy, but I’m not familiar with how to monitor properties that belong to parent classes. Unlike IsMouseDirectlyOver, IsMouseOver doesn’t have a changed event attached.

  • 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-05T11:06:06+00:00Added an answer on June 5, 2026 at 11:06 am

    You can use styles to react to when IsMouseOver is changed.

    <Window.Resources>
         <Style x:Key="RectStyle" TargetType="Rectangle">
              <Style.Triggers>
                   <Trigger Property="IsMouseOver" Value="True">
                        <!-- react to property change here -->
                   </Trigger>
              </Style.Triggers>
         </Style>
     </Window.Resources>
    

    And later attach the style to an element:

    <Rectangle Style="{StaticResource RecStyle}" Width="100" Height="100" Fill="Black" />
    

    Edit:

    If you want to call code from within a style, the solution is rather complex.

    First, you have to create a custom UserControl class and give it an attached property. Whenever the attached property is changed, you can use the property changed callback. Here’s the *.xaml.cs file, just keep the default .xaml file:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    
    namespace ExampleApp
    {
        /// <summary>
        /// Interaction logic for MouseOverWrapper.xaml
        /// </summary>
        public partial class MouseOverWrapper : UserControl
        {
    
            public static readonly DependencyProperty MouseIsOverProperty;
    
            static MouseOverWrapper()
            {
                MouseIsOverProperty = DependencyProperty.RegisterAttached(
                    "MouseIsOver", typeof(bool), typeof(MouseOverWrapper),
                    new FrameworkPropertyMetadata(false, OnMouseIsOverChanged));
            }
    
            public static bool GetMouseIsOver(UIElement element)
            {
                return (bool)element.GetValue(MouseIsOverProperty);
            }
    
            public static void SetMouseIsOver(UIElement target, bool value)
            {
                target.SetValue(MouseIsOverProperty, value);
            }
    
            private static void OnMouseIsOverChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                // handle code here. example:
                if ((bool)e.NewValue == true)
                    ((Rectangle)d).Fill = Brushes.Yellow;
                else
                    ((Rectangle)d).Fill = Brushes.Black;
            }
    
            public MouseOverWrapper()
            {
                InitializeComponent();
            }
        }
    }
    

    You’ll then have to wrap the elements you want to react to in your custom control and make the style change the attached property of that custom control. Example:

    <Window x:Class="ExampleApp.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:local="clr-namespace:ExampleApp"
            Title="MainWindow" Height="350" Width="525">
        <Window.Resources>
            <Style x:Key="RecStyle" TargetType="Rectangle">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="local:MouseOverWrapper.MouseIsOver" Value="True" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Window.Resources>
        <local:MouseOverWrapper>
            <Rectangle Style="{StaticResource RecStyle}" Width="100" Height="100" Fill="Black" />
        </local:MouseOverWrapper>
    </Window>
    

    Add all your code into the OnMouseOverIsChanged function, and this should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use roll apply like functionality on non time series data but
I'd like to add IDLE-like functionality to C# WinForms application, but I don't quite
I want to implement simple LINQ-to-SQL-like functionality in my .net application. For example i
I would like to implement some Drag-select functionality into a project of mine but
I've found a few methods online on how to implement property-like functionality in c++.
I want a shopify like functionality in my app which I am developing. Shopify
I want to add a like functionality to a blog I am creating in
I want to acheive the functionality like this how can i do this. DECLARE
I have a web app for commercial property management that needs spreadsheet-like functionality for
How to build Opera unite like functionality using .NET? When we run opera browser

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.