Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - Binding StringFormatting Not Working

I need to append a simple string to my commandparameter but doesnt work. Does StringFormat support this or am I doing anything 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>
like image 453
Everything Matters Avatar asked Jan 28 '26 06:01

Everything Matters


1 Answers

The StringFormat property only works when the Type of the target property is string. In this case the target property is CommandParameter which is of type object. You'll need to create your own IValueConverter and use that as the Converter for your binding. There is an example IValueConverter similar to what you need in the SL docs for IValueConverter.

like image 161
AndrewS Avatar answered Jan 30 '26 00:01

AndrewS



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!