Get event sender from event : Event « Windows Presentation Foundation « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Windows Presentation Foundation » Event 
24.119.8.Get event sender from event
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
  mc:Ignorable="d" Background="#FFFFFFFF" x:Name="DocumentRoot"
  x:Class="InputExamples.EventHandling" Width="640" Height="480">
  <Grid.Resources>
    <Storyboard x:Key="OnLoaded"/>
  </Grid.Resources>
  
  <Grid.ColumnDefinitions>
    <ColumnDefinition/>
  </Grid.ColumnDefinitions>
  <Grid.RowDefinitions>
  <RowDefinition/>
  </Grid.RowDefinitions>
  <Button HorizontalAlignment="Left" 
          VerticalAlignment="Top" 
          Width="106" 
          Height="28" 
          x:Name="ClickButton1" 
          Content="Click Me!" 
          Click="ClickHandler" PreviewMouseUp="ButtonMouseUpHandler"/>
  <Button d:LayoutOverrides="Width, Height" 
          HorizontalAlignment="Left" 
          VerticalAlignment="Top" 
          Margin="20" 
          Width="106" 
          Height="28" 
          x:Name="ClickButton2" 
          Content="Click Me!" 
          Click="ClickHandler" 
          PreviewMouseUp="ButtonMouseUpHandler"/>
</Grid>

//File:Window.xaml.cs
using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;

namespace InputExamples
{
  public partial class EventHandling
  {
    public EventHandling()
    {
      this.InitializeComponent();
    }
    
    private void ClickHandler(object sender, RoutedEventArgs e)
    {
          Button clicked = e.Source as Button;
          MessageBox.Show(String.Format("{0} was clicked!", clicked.Name));
    }

    private void ButtonMouseUpHandler(object sender, MouseButtonEventArgs e)
    {
          Button clicked = sender as Button;
          clicked.Content = String.Format("{0} clicked", clicked.Name);
    }
  }
}
WPF Get Event Sender From Event
24.119.Event
24.119.1.Cast event sender to a controlCast event sender to a control
24.119.2.Press F1 to get helpPress F1 to get help
24.119.3.Raise the PropertyChanged eventRaise the PropertyChanged event
24.119.4.Get the event sender nameGet the event sender name
24.119.5.Use Ellipse event delegateUse Ellipse event delegate
24.119.6.Halting event routing with HandledHalting event routing with Handled
24.119.7.Use Ellipse.AddHandler to add handler to Ellipse objectsUse Ellipse.AddHandler to add handler to Ellipse objects
24.119.8.Get event sender from eventGet event sender from event
24.119.9.Handle the ContentRendered eventHandle the ContentRendered event
24.119.10.Find source element of an element in event handler by casintFind source element of an element in event handler by casint
24.119.11.Add an event handler to an element using codeAdd an event handler to an element using code
24.119.12.Handles the Click event on the UniformGridHandles the Click event on the UniformGrid
24.119.13.Mark the text control as being changed to prevent any text content or selection changed eventsMark the text control as being changed to prevent any text content or selection changed events
24.119.14.Check handler event senderCheck handler event sender
24.119.15.Generate Click Events Repeatedly While a Button Is ClickedGenerate Click Events Repeatedly While a Button Is Clicked
24.119.16.Raise the ScrollChanged event of a ScrollViewerRaise the ScrollChanged event of a ScrollViewer
24.119.17.Event firing sequenceEvent firing sequence
24.119.18.ToolBar and event handlerToolBar and event handler
24.119.19.Cancel event by setting CanExecute and Handled to falseCancel event by setting CanExecute and Handled to false
24.119.20.Activated and Deactivated events monitors the activation status of an application.Activated and Deactivated events monitors the activation status of an application.
24.119.21.Event sender, event source and event original sourceEvent sender, event source and event original source
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.