【问题标题】:WPF - Binding StringFormatting Not WorkingWPF - 绑定 StringFormatting 不起作用
【发布时间】:2011-04-21 05:33:09
【问题描述】:

我需要将一个简单的字符串附加到我的命令参数中,但它不起作用。 StringFormat 支持这个还是我做错了什么?

  <DataTemplate x:Key="ClickableHeaderTemplate">
              <Button x:Name="btn" Content="{Binding}" Background="Transparent"
                  Command="{Binding DrilldownHeaderClicked}" 
                     Tag="{Binding RelativeSource={RelativeSource Self}, Path=Content}"
                     CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=Tag, StringFormat=somestring\{0\}}"> --- formatting doesnt work. tried without escape seq as well as in 'somesting{0}'. 
                 </Button>
            </DataTemplate>

【问题讨论】:

    标签: wpf wpf-controls binding wpftoolkit wpfdatagrid


    【解决方案1】:

    StringFormat 属性仅在目标属性的类型为字符串时有效。在这种情况下,目标属性是对象类型的 CommandParameter。您需要创建自己的 IValueConverter 并将其用作绑定的转换器。在SL docs for IValueConverter 中有一个类似于您需要的示例 IValueConverter。

    【讨论】:

      猜你喜欢
      • 2011-10-02
      • 1970-01-01
      • 2012-10-20
      • 2014-08-25
      • 1970-01-01
      • 2014-04-10
      • 2014-09-09
      相关资源
      最近更新 更多