Caliburn笔记-Action简写(wpf框架)
2009-12-30 10:29 Clingingboy 阅读(1697) 评论(0) 编辑 收藏 举报
http://caliburn.codeplex.com/wikipage?title=Action%20Basics&referringTitle=Documentation
public void Demo() { MessageBox.Show("hello"); }
1.传递方法
<Button Content="Demo" cal:Message.Attach="Demo" />
2.使用事件传递
(1)
<Button Content="Demo" cal:Message.Attach="[Event Click] = [Action Demo]" />
(2)附加事件(好像有bug)
<StackPanel cal:Message.Attach="[AttachedEvent Button.Click] = [Action Demo]"> <Button Content="Divide (Stack)" /> <Button Content="Divide (Stack)" /> </StackPanel>
3.事件连写(分号相隔)
<Button Content="Demo" cal:Message.Attach="[Event Click] = [Action Demo];[Event Loaded] = [Action Demo]" />
其他事件请参考此处
http://caliburn.codeplex.com/wikipage?title=Message%20Triggers&referringTitle=Documentation
4.参数传递
(1)
public void Demo(string str) { MessageBox.Show(str); }
<Button Content="Demo" cal:Message.Attach="Demo('hello')" />
(2)支持元素对象获取
<TextBox x:Name="demoBox" /> <Button Content="Demo" cal:Message.Attach="Demo(demoBox.Text)" />
(3)支持内置参数解析
http://caliburn.codeplex.com/wikipage?title=Parameters&referringTitle=Documentationpublic void Demo(object sender,EventArgs args) { }
<Button Content="Demo" cal:Message.Attach="Demo($source,$eventArgs)" />
(4)支持返回值传递
public int Demo() { return 1; }
<TextBox x:Name="demoBox" /> <Button Content="Demo" cal:Message.Attach="[Action Demo : demoBox.Text]" />
(5)支持绑定模式
<TextBox x:Name="demoBox" /> <Button Content="Demo" cal:Message.Attach="[Action Demo(demoBox.Text:TwoWay)]" />