Caliburn第3部分 事件 参数
来源:互联网 发布:不需要交钱的网络兼职 编辑:程序博客网 时间:2024/06/05 00:06
有参数的事件绑定
长语法的优点是它的兼容性与Microsoft Expression Blend中。 简短的语法是巨大的,如果你在使用设计不感兴趣,并希望保持短
The advantage of the long syntax is its compatability with Microsoft Expression Blend. The short syntax is great if you’re not interested in using a designer and want to keep things short and sweet.
长语法
View中添加
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"xmlns:cal=http://www.caliburnproject.org
<RepeatButton Content="Up" Margin="15" VerticalAlignment="Top"> <i:Interaction.Triggers> <i:EventTrigger EventName="Click"> <cal:ActionMessage MethodName="IncrementCount" /> </i:EventTrigger> </i:Interaction.Triggers></RepeatButton>
What we have done here is used System.Windows.Interactivity triggers to hook up an event to a method.
EventTrigger 监听事件类型 EventName
ActionMessage 事件处理方法 MethodName
加入参数的事件
public void IncrementCount(int delta){ Count += delta;}
<cal:ActionMessage MethodName="IncrementCount"> <cal:Parameter Value="1" /></cal:ActionMessage>
The Value property of the Caliburn Micro Parameter is a dependency property, which means it also supports the usual WPF data binding. This allows you to use it in all sorts of different scenarios you come across.
2.短语法
This time we only need to add the Caliburn Micro namespace, and replace the repeat button with this new one:
<RepeatButton Content="Up" Margin="15" VerticalAlignment="Top" cal:Message.Attach="[Event Click] = [Action IncrementCount]" />
Including an event parameter using Message.Attach will look like this:
cal:Message.Attach="[Event Click] = [Action IncrementCount(1)]"
如果不显示设置参数 Caliburn会自动设置参数
If you do not explicitly specify a parameter, Caliburn Micro will look at the parameter name in the method signiture and try find any user control in the view that matches this name (ignoring the case).If a matching user control is found, an appropriate property on the control will be used to provide the parameter.For example, if the user control is a TextBlock, the Text property value will be used as the parameter. Again, Caliburn Micro can automatically convert strings to ints and so on if necessary.
Caliburn会从当前的Controls寻找到与方法参数名相同的控件,并将控件合适的属性赋给参数。
<UniformGrid Columns="2" VerticalAlignment="Bottom"> <Slider Name="Delta" Minimum="0" Maximum="5" Margin="15" /> <Button Name="IncrementCount" Content="Increment" Margin="15" /></UniformGrid>
在这里,我只涵盖Caliburn提供的挂接事件的支持。 其他一些主题:
- 设定行动目标
- 特殊参数值的数据绑定
- 行动冒泡
- 行动警卫参数
- Setting action targets
- Special parameter values for data binding
- Action bubbling
- Action guards with parameters
Caliburn文档:
http://caliburnmicro.codeplex.com/wikipage?title=Cheat%20Sheet&referringTitle=Documentation
http://www.mindscapehq.com/blog/index.php/2012/1/24/caliburn-micro-part-3-more-about-events-and-parameters/
- Caliburn第3部分 事件 参数
- Caliburn第4部分 事件聚合器
- Caliburn第2部分 数据绑定和事件
- Caliburn第1部分:入门
- JSR 286 Portlet 的新特性,第 2 部分: 资源服务、事件与共享呈现参数
- 掌握 Dojo 工具包,第 3 部分: Dojo 事件机制
- 掌握 Dojo 工具包,第 3 部分: Dojo 事件机制
- 数据源控件,第 2 部分:参数
- JSF 2 简介,第 3 部分: 事件处理、JavaScript 和 Ajax
- JSF 2 简介,第 3 部分: 事件处理、JavaScript 和 Ajax
- 使用 StAX 解析 XML,第 3 部分: 使用定制事件和编写 XML
- 轻松学习 JavaScript——第 3 部分:函数中的默认参数
- 第4部分 事件-----《Microsoft.NET框架程序设计》
- 第4部分 事件2-----《Microsoft.NET框架程序设计》
- 反向Ajax,第5部分:事件驱动的Web开发
- 反向Ajax,第5部分:事件驱动的Web开发
- 反向Ajax,第5部分:事件驱动的Web开发
- 反向Ajax,第5部分:事件驱动的Web开发
- 实现自己的扫描hibernate 标签类
- vc链接静态库的时候要注意的问题
- 陕西大荔一名警察参与绑架勒索162万后仍撕票-绑架-撕票-民警
- windows 性能计数器
- UDID入门,了解Apple的数据外泄状况
- Caliburn第3部分 事件 参数
- frame,iframe和frameset简单介绍
- 【php】HTTP消息头中的“Cache-control”
- 关于QscrollArea的使用
- sed 在特定行 插入特定内容
- [转]首次发现一行星的天空上有“4个太阳”
- 把CSV文件导入到SQL Server表中的方法
- oracle查询IP地域信息
- 一个高考的"黑客"故事:用2B铅笔"注入"阅卷系统(只有佩服。。)