c# - WPF 命令和参数

标签 c# .net wpf xaml

我发现 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)。

有人看到一个明显的改进方法吗?

最佳答案

让我向您介绍我的开源项目 Caliburn。您可以在 here 找到它.最有助于解决您问题的功能已简要记录 here

关于c# - WPF 命令和参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/151700/

相关文章:

c# - 从 ListBoxItem 获取 ListBox 对象

c# - 如何为 WPF 饼图中的饼图切片设置默认颜色

c# - 有没有办法通过数据注释来验证一个日期属性是否大于或等于另一个日期属性?

c# - 无需数据库即可生成唯一编号

c# - 没有可见形式的 WndProc?

C# 绑定(bind)不起作用

c# - ListView 内的组合框绑定(bind) WPF

c# - 将短语翻译与 String.Format 集成

c# - 找不到应用程序依赖项 list (project.deps.json) 中指定的程序集

c# - 如何在 Entity Framework 中设置两个相同类型的导航属性