Wpf provides very interesting things, till now we can draw some 2D shapes like rectangle, ellipse etc. in simple windows application and it is big deal to implement features on shapes like other window control such as event handling. Suppose you create a rectangle on the form and you want to implement click or mouse event, on there it is big problem with 2 D shapes. But In WPF shapes are that they are not just for display; shapes implement many of the features that you expect from controls, including keyboard and mouse input. The following example shows the MouseUp event of an Ellipse being handled.
[XAML]
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="wpfEllipse" Width="209" Height="156"> <Ellipse Name="wpfEllipse" Fill="red" MouseUp="wpfEllipse_MouseUp" Width="150" Height="50" /> </Window>
[VB.Net]
Imports System.Windows Imports System.Windows.Input Class MainWindow Private Sub wpfEllipse_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) MessageBox.Show("Welcome to WPF") End Sub End Class
The following figure shows what is produced by the above code.