怎么样在 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">
<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.
- ››怎么样在sharepoint 2010 中操作List的办法
- ››创建基于PPTP的站点到站点VPN连接:ISA2006系列之...
- ››创建基于L2TP的站点到站点的VPN连接:ISA2006系列...
- ››创建一个Twisted Reactor TCP服务器
- ››创建Windows Mobile上兼容性好的UI 程序
- ››创建android的Service
- ››创建远古部落环境与原住民角色
- ››创建并扩展Apache Wicket Web应用
- ››创建不在任务条中显示窗口按钮的应用
- ››创建 Android 文件系统(Root file system)
- ››Classworking 工具箱: 分析泛型数据结构
- ››Classworking 工具箱: 将 aspect 放到 werk 中
更多精彩
赞助商链接