2010-10-05 94 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中需要的內容。