WPF - StringFormatting binding does not work

I need to add a simple line to my command parameter, but it doesn’t work. Does StringFormat support this or am I doing something wrong?

  <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>
+3
source share
1 answer

The StringFormat property only works if the Type of the target property is a string. In this case, the target property is CommandParameter, which has an object type. You will need to create your own IValueConverter and use it as a converter for binding. The IValueConverter example is similar to the one you need in the SL docs for IValueConverter .

+4

Source: https://habr.com/ru/post/1768039/


All Articles