【发布时间】:2013-03-15 10:16:32
【问题描述】:
我想在任何绑定参数更改时调用 CanExpressionSave 方法
在 caliburn micro 中使用长语法设置绑定。
<controls:ImageButton DockPanel.Dock="Right" Image="/Resources/Save.png" AlternativeImage="/Resources/SaveDisabled.png"
Text="Save" Style="{StaticResource ControlButtonStyle}" x:Name="ExpressionSave">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cal:ActionMessage MethodName="ExpressionSave">
<cal:Parameter Value="{Binding ElementName=firsttag, Path=Text}"></cal:Parameter>
<cal:Parameter Value="{Binding ElementName=firstoperation, Path=Content}"></cal:Parameter>
<cal:Parameter Value="{Binding ElementName=secondtag, Path=Text}"></cal:Parameter>
<cal:Parameter Value="{Binding ElementName=SecondOperation, Path=Content}"></cal:Parameter>
<cal:Parameter Value="{Binding ElementName=thirdtag, Path=Text}"></cal:Parameter>
</cal:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
</controls:ImageButton>
代码隐藏:
public void ExpressionSave(string firsttag, string firstoperation, string secondtag,
string secondoperation, string thirdtag){ }
public bool CanExpressionSave(string firsttag, string firstoperation, string secondtag,
string secondoperation, string thirdtag){}
【问题讨论】:
-
当这些属性发生变化时,您是否针对这些属性提出了属性更改通知?通过在您的 VM 中实现
INotifyPropertyChange或从Caliburn.Micro.PropertyChangedBase继承并调用NotifyOfPropertyChange(() => SomeProperty); -
感谢您的快速回复。我发现了错误,但无法在 8 小时前回答我的问题 :)
-
问题出在绑定的几个外壳中。我以为我从参数中获取了正确的数据,因为我不期望任何值,但是由于绑定错误而得到的值。 xaml 和上面的代码是有效的,因为 CanExpressionSave 将被 Caliburn 隐式绑定。这意味着对任何绑定属性的任何更改都将触发 CanExpressionSave。希望这对某人有帮助:)
-
总是有助于密切关注调试窗口,因为默认情况下会在其中获取数据绑定异常(假设您没有使用 VS Express)。我经常想念它们并挠头,因为绑定不是最容易调试的东西!
-
是的,我绝对应该养成检查输出窗口的习惯。如果我先检查一下,我会立即发现:D
标签: wpf caliburn.micro