Reputation: 1704
I have a binding with converter. I want to pass the "#,,.0M" format string as converter parameter.
This xaml in not valid:
<local:SalesPerformanceControl FirstSalesVolume="{Binding Path=TodaySalesVolume, Converter={StaticResource ResourceKey=decimalToFormatedStringConverter}, ConverterParameter=#,,.0M}"/>
Error:
The type '' was not found.
How to pass this string correctly?
Upvotes: 2
Views: 7090
Reputation: 18578
Either use single quotes on the string to be passed:
<local:SalesPerformanceControl FirstSalesVolume="{Binding Path=TodaySalesVolume, Converter={StaticResource ResourceKey=decimalToFormatedStringConverter}, ConverterParameter='#,,.0M'}"/>
OR use elaborate syntax to bind like below:
<local:SalesPerformanceControl>
<local:SalesPerformanceControl.FirstSalesVolume>
<Binding Path="TodaySalesVolume" Converter="{StaticResource decimalToFormatedStringConverter}" ConverterParameter="#,,.0M" />
</local:SalesPerformanceControl.FirstSalesVolume>
</local:SalesPerformanceControl>
Upvotes: 7
Reputation: 940
One of the way can be declare your string in resources and pass it to your converter.
<UserControl.Resources>
<sys:String x:Name="strParam">#,,.0M</sys:String>
</UserControl.Resources>
Add like as bellow
<local:SalesPerformanceControl FirstSalesVolume="{Binding Path=TodaySalesVolume, Converter={StaticResource ResourceKey=decimalToFormatedStringConverter}, ConverterParameter={StaticResource strParam}}"/>
may help you
Upvotes: 1
Reputation: 6547
Try saving the string as a resource.
First add the following xmlns declaration
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Then save the string in the resources
<sys:String x:Key="format">#,,.0M</sys:String>
And use it as follows
<local:SalesPerformanceControl FirstSalesVolume="{Binding Path=TodaySalesVolume, Converter={StaticResource ResourceKey=decimalToFormatedStringConverter}, ConverterParameter={StaticResource ResourceKey=format}}"/>
Upvotes: 0