WPF SDK研究 Intro(4) QuickStart4

QuickStart4
    This sample shows you how to implement a button with an associated Click event handler.
    本例介绍如何在xaml的button上绑定后台的事件

    xaml代码:
<Page    
  xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class
="QuickStart_4.Page1">
    
<StackPanel>
        
<Button HorizontalAlignment="Left"
                Width
="100"
                Margin
="10,10,10,10"
                Click
="HandleClick"
                Name
="Button1">Click Me</Button>
    
</StackPanel>
</Page>

    后台代码:
namespace QuickStart_4
{
    
public partial class Page1 : Page
    
{
        
void HandleClick(object sender, RoutedEventArgs e)
        
{
            Button1.Content 
= "Hello World";
        }

    }

}

    分析如下:
        xaml代码的Page标签,x:Class="QuickStart_4.Page1",指定了这个xaml文件将编译到QuickStart_4.Page1中(没有这个属性的xaml文件是在运行期动态编译的)。通过Button的Click事件,指定后台的相应方法。
        注意后台代码的事件方法,使用的是RoutedEventArgs参数,这牵扯到WPF中新的事件机制。
原文地址:https://www.cnblogs.com/Jax/p/1096747.html