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

怎么样在 x:Class中创建Event Handlers

 2008-10-04 11:37:52 来源:WEB开发网   
核心提示: VB <Canvas x:Name="Button2" Canvas.Top="50" Width="100" Height="30" Background="Gray"><

VB

<Canvas x:Name="Button2" Canvas.Top="50" Width="100" Height="30" Background="Gray">
 <TextBlock>Click Me Too</TextBlock>
</Canvas>

编辑 Page1.xaml.cs. 在 EventHandlingCanvas 类的默认为空的构造函数中, 关联一个handle给 Loaded 事件. (你将在接下来的步骤中定义 handler的内容.)

CS

public EventHandlingCanvas()
{
  this.Loaded+=new EventHandler(EventHandlingCanvas_Loaded);
}

定义 EventHandlingCanvas_Loaded handler, 它是你的Button2的引用.

CS

void EventHandlingCanvas_Loaded(object sender, EventArgs e)
{
  Button2.MouseLeftButtonUp+=new MouseEventHandler(OnClick);
}

保存这些文件并编译程序. 当你在浏览器中载入 HTML 页然后单击第二个Click me 时, 你可以看到它的颜色也改变了.

在Visual Basic关联 Event Handlers(暂不译)

Visual Basic has a different syntax for attaching handlers that relies on the keywords With事件 and Handles. In the case of named elements that are created in XAML, you will not directly see the With事件 keywords applied. In a Silverlight Visual Studio project, With事件 keywords are added and field references (for accessing your named XAML elements in code) are created through generated code by default. (Remember the prewired Loaded handler in the code 文件s that was mentioned earlier? That prewired Loaded handler and the partial class definition are both necessary so that the code generation can work.) Handles syntax will work only if you give the source element a unique x:Name; that name becomes your instance reference when you declare Handles.

上一页  1 2 3 4 5 6  下一页

Tags:怎么样 Class 创建

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接