WEB开发网
开发学院图形图像Flash 怎么样在 x:Class中创建Event Handlers 阅读

怎么样在 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

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.

上一页  1 2 3 4 5 6 

Tags:怎么样 Class 创建

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接