WPF事件注冊特點介紹
作者:佚名 
  在WPF中,WPF事件注冊的參數(shù)和以往有些不太相同,它的參數(shù)變?yōu)镽outedEventArgs。我們以一段代碼示例來講解,方便大家理解。
 WPF注冊事件是一個比較基礎(chǔ)的知識點。對于初學(xué)者來說,掌握這一技巧的應(yīng)用,是非常有必要的。在這里我們就來具體的了解一下相關(guān)知識。#t#
WPF事件注冊與以往的有些區(qū)別,事件的參數(shù)變?yōu)椋篟outedEventArgs。
示例: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>
 
后臺關(guān)聯(lián)的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事件注冊的一些具體介紹,希望對大家有用。
責(zé)任編輯:曹凱 
                    來源:
                    CSDN
 














 
 
 
 
 
 
 