2010-10-05 93 views
3

我需要追加一个简单的字符串到我的commandparameter,但不起作用。 StringFormat支持这个还是我做错了什么?WPF - 绑定StringFormatting不工作

<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> 

回答

4

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