C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Here: We add the MouseEnter and MouseLeave attributes. We have Visual Studio create the event handlers.
And: We set the Fill to "Salmon" for a good fishy quality, but leave the "Stroke" as "Black". Width and Height are set to 100 each.
Example markup: XAML
<Window x:Class="WpfApplication26.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Ellipse Fill="Salmon"
HorizontalAlignment="Left"
Height="100"
Margin="10,10,0,0"
Stroke="Black"
VerticalAlignment="Top"
Width="100"
MouseEnter="Ellipse_MouseEnter"
MouseLeave="Ellipse_MouseLeave"/>
</Grid>
</Window>
Example code: C#
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;
namespace WpfApplication26
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Ellipse_MouseEnter(object sender, MouseEventArgs e)
{
// ... Change Ellipse to a blue color.
var ellipse = sender as Ellipse;
ellipse.Fill = Brushes.AliceBlue;
}
private void Ellipse_MouseLeave(object sender, MouseEventArgs e)
{
// ... Change Ellipse to a red color.
var ellipse = sender as Ellipse;
ellipse.Fill = Brushes.Salmon;
}
}
}
And: In MouseLeave, we take the same exact steps, except we use Brushes.Salmon to return our Ellipse to a fish color.
Note: MouseEnter and MouseLeave could be combined into a single method, one that changes Salmon to AliceBlue, and vice versa.