WPF注册事件是一个比较基础的知识点。对于初学者来说,掌握这一技巧的应用,是非常有必要的。在这里我们就来具体的了解一下相关知识。#t#
WPF事件注册与以往的有些区别,事件的参数变为:RoutedEventArgs。
示例:XAML端代码:
- Window x:Class="Hello.Window1"
- xmlns="http://schemas.microsoft
.com/winfx/2006/xaml/presentation" - xmlns:x="http://schemas.microsoft.
com/winfx/2006/xaml" - Title="Hello" Height="300"
Width="300" - >
- < Grid>
- < Button Height="23" Margin="12,52,0,0"
Name="btnOK" VerticalAlignment="Top"
HorizontalAlignment="Left" Width="75"
Click="btnOK_Click" >确定< /Button> - < TextBox Height="26" Margin=
"105,51,87,0" Name="txtHello"
VerticalAlignment="Top" >< /TextBox> - < /Grid>
- < /Window>
后台关联的C#代码如下:
- using System;
- using System.Windows;
- namespace Hello
- ...{
- /**//// < summary>
- /// Interaction logic
for Window1.xaml- /// < /summary>
- public partial class
Window1 : System.Windows.Window- ...{
- public Window1()
- ...{
- InitializeComponent();
- //btnOK.Click += new
RoutedEventHandler(SetText);- }
- public void btnOK_Click(object
sender, RoutedEventArgs e)- ...{
- txtHello.Text = "Hello World!";
- }
- }
- }
以上就是WPF事件注册的一些具体介绍,希望对大家有用。