In this article I am going to show how a rectangle's color change as mouse do different. For this application on my window I use a rectangle. Here in rectangle tag we found many properties like as mousemove, mouseexit, mouseclick etc. On any event of mouse like as mouseup, mousedown, mouseclick etc. we can perform any type of operation. Here on every different behavior of mouse I am changing the color of rectangle.
For this I design a window as in window.xml:
<Window x:Class="Mouseoperation.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Mouseoperation" Height="300" Width="359">
<Grid>
<Ellipse />
<Rectangle Name="MyRect" Height="100" Width="300" StrokeThickness="10" Stroke="Blue" Fill="Red" MouseDown="MyRectMouseDown" MouseEnter="MyRectMouseEnter" MouseLeave="MyRectMouseLeave" MouseWheel="MyRectMouseWheel">
</Rectangle>
</Grid>
</Window>
The window will become like as:

Figure 1: Our designing window
This is the window1.xaml.cs code, where we define that how the color of rectangle will change on every different behavior of Mouse.
using System;
using System.Collections.Generic;
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.Shapes;
namespace Mouseoperation
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : System.Windows.Window
{
public Window1()
{
InitializeComponent();
}
void MyRectMouseDown(object sender, System.EventArgs e)
{
MyRect.Fill = Brushes.Black;
}
void MyRectMouseEnter(object sender, System.EventArgs e)
{
MyRect.Fill = Brushes.Aqua;
}
void MyRectMouseLeave(object sender, System.EventArgs e)
{
MyRect.Fill = Brushes.DarkSeaGreen;
}
void MyRectMouseWheel(object sender, System.EventArgs e)
{
MyRect.Fill = Brushes.Magenta;
}
void MyRectMouseButtonLeft(object sender, System.EventArgs e)
{
MyRect.Fill = Brushes.MediumVioletRed;
}
}
}
When we run the Program:

Figure 2 In Running Mode Application
When mouse comes inside the Rectangle:

Figure 3 when mouse comes inside the Rectangle the color become change
When Mouse clicked inside the Rectangle:

Figure 4 when mouse clicked inside the Rectangle the color become change when mouse comes outside the rectangle.

Figure 5: When mouse go outside the Rectangle the color becomes change.