怎么样在 x:Class中创建Event Handlers
2008-10-04 11:37:52 来源:WEB开发网To change the XAML and the 托管 code
Edit Page1.xaml. After the first Canvas "button", insert another similar button that does not have a XAML event handler in it.
CS
<Canvas x:Name="Button2" Canvas.Top="50" Width="100" Height="30" Background="Gray">
<TextBlock>Click me too</TextBlock>
</Canvas>
VB
<Canvas x:Name="Button2" Canvas.Top="50" Width="100" Height="30" Background="Gray">
<TextBlock>Click Me Too</TextBlock>
</Canvas>
Edit Page1.xaml.vb. Add another handler that does essentially the same thing as the first one. This time, use Handles to assign the handler to the specific MouseLeftButtonUp event on the Button2 instance.
VB
Private Sub Button2_MouseLeftButtonUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles Button2.MouseLeftButtonUp
Dim redBrush As New SolidColorBrush
redBrush.Color = Colors.Red
Me.Button2.Background = redBrush
Dim tb As TextBlock = Me.Button2.Children(0)
tb.Text = "Clicked..."
End Sub
note
If you give the first button the x:Name聽Button1, and the handler implementations are identical in signature as well as in function, you can designate more than one instance to be handled by the same handler, for example: 鈥?Handles Button1.MouseLeftButtonUp, Button2.MouseLeftButtonUp. If you do this, you will also want to remove the MouseLeftButtonUp event attribute from Button1, because now you are declaring the handling in code.
- ››创建SQL2005自动备份,定期删除的维护计划
- ››Classloader和线程
- ››创建动态表单 javascript
- ››怎么样在sharepoint 2010 中操作List的办法
- ››创建基于PPTP的站点到站点VPN连接:ISA2006系列之...
- ››创建基于L2TP的站点到站点的VPN连接:ISA2006系列...
- ››创建一个Twisted Reactor TCP服务器
- ››创建Windows Mobile上兼容性好的UI 程序
- ››创建android的Service
- ››创建远古部落环境与原住民角色
- ››创建并扩展Apache Wicket Web应用
- ››创建不在任务条中显示窗口按钮的应用
更多精彩
赞助商链接