Caliburn第3部分 事件 参数
2012-10-16 16:59
190 查看
有参数的事件绑定
长语法的优点是它的兼容性与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中添加
What we have done here is used System.Windows.Interactivity triggers to hook up an event to a method.
EventTrigger 监听事件类型 EventName
ActionMessage 事件处理方法 MethodName
加入参数的事件
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:
Including an event parameter using Message.Attach will look like this:
如果不显示设置参数 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寻找到与方法参数名相同的控件,并将控件合适的属性赋给参数。
在这里,我只涵盖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/
长语法的优点是它的兼容性与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第4部分 事件聚合器
- JSR 286 Portlet 的新特性,第 2 部分: 资源服务、事件与共享呈现参数
- WMS授权插件AuthorizeEvent中部分事件参数说明
- Caliburn第2部分 数据绑定和事件
- MPlayer参数使用介绍(部分)(中文)
- 事件event参数,火狐与ie的区别
- 复杂事件处理引擎—Esper参考(事件部分)
- JavaScript在for循环中绑定事件解决事件参数不同的情况
- 在dw的itemchanged事件里面,修改当前参数data
- 反向Ajax,第3部分:Web服务器和Socket.IO
- 如何为事件传递参数
- 在js循环中如何给a标签的点击事件的方法参数赋值有效
- Springboot用@PathVariable传参,最后一个参数会丢失小数点后面的部分
- 第3部分:更多DI的知识
- View的事件体系之View的位置参数
- Android实现TextView部分文本监听单击事件
- HTML5基础,第3部分:HTML5 API的威力
- 根据Gridview列事件参数得到该行对象
- 《开源合辑-(游戏/娱乐)之(C#)》 第3部分
- Windows到Linux之旅:第3部分.Webmin简介