【发布时间】:2010-09-14 04:21:18
【问题描述】:
我发现 WPF 命令参数是一个限制。也许这表明我将它们用于错误的目的,但在我放弃并采取不同的策略之前,我仍在尝试。
我为executing commands asynchronously 组装了一个系统,但是很难使用任何需要输入数据的东西。我知道 WPF 命令的一种常见模式是传入this。但是this 根本不适用于异步命令,因为所有依赖属性都无法访问。
我最终得到这样的代码:
<Button Command="{Binding ElementName=servicePage, Path=InstallServiceCommand}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource InstallServiceParameterConverter}">
<MultiBinding.Bindings>
<Binding ElementName="servicePage" Path="IsInstalled"/>
<Binding ElementName="localURI" Path="Text"/>
<Binding ElementName="meshURI" Path="Text"/>
<Binding ElementName="registerWithMesh" Path="IsChecked"/>
</MultiBinding.Bindings>
</MultiBinding>
</Button.CommandParameter>
</Button>
还需要InstallServiceParametersConverter类(加上InstallServiceParameters)。
任何人都看到了改进这一点的明显方法吗?
【问题讨论】:
-
我不明白为什么这是个问题。自从我记得使用它以来,我就一直使用这样的 WPF。这也意味着您可以随时重复使用具有不同数据源的转换器,并且不受
this类型的约束。你能解释一下为什么你觉得这是错误的吗?