【问题标题】:How to supply a string literal value as a binding in WPF如何在 WPF 中提供字符串文字值作为绑定
【发布时间】:2013-07-18 21:00:00
【问题描述】:

编辑:

我之前的问题也提到了命令,但正如下面的评论中指出的那样,这是不必要的并且增加了噪音。


这更像是一个 XAML 语法问题,所以它可能是微不足道的。 我想知道如何将字符串文字作为 WPF 中绑定的值传递。

如果从 XAML 的上下文中已经知道该值,是否可以直接将其值直接分配给绑定,而不是使用路径和其他方式? 如果是这样,这种情况下的语法是什么?

<MultiBinding.Bindings>
    <!-- First binding, a textbox  -->
    <Binding  RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type TextBox}}"/>
    <!-- Second binding, I want to pass a string as is, for instance, "Description" -->
    <!-- The proper syntax for the line below is what I am after -->
    <Binding Value="Description"/>
</MultiBinding.Bindings>

【问题讨论】:

  • 不能只使用CommandParameter属性吗?
  • CommandParameter 属性已设置为 MultiBinding。为简单起见,我没有发布包含它的整个代码 sn-p。对于可能造成的混乱,我们深表歉意。

标签: wpf string xaml parameters command


【解决方案1】:

这是

<Binding Source="Description"/>

Source 可以是任何类型,因此在解释为字符串的属性语法中,如果未指定 Path,则绑定的值就是源。

这也是一个多重绑定,我不会谈论命令参数,因为这与此事无关......

【讨论】:

  • 完美!就是这样。谢谢!
猜你喜欢
  • 1970-01-01
  • 2019-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-20
  • 2019-10-05
  • 1970-01-01
  • 2011-04-27
相关资源
最近更新 更多