Binding a ConverterParameter to a Resource file in Silverlight 4
I'm trying to create a common converter that will take in a string from a resource resx file (the app has to be localizable) as a parameter.
<TextBlock
ToolTip开发者_如何学PythonService.ToolTip="{Binding IsInUse, ConverterParameter={Binding Path=WhereUsedIndicatorTooltips, Source={StaticResource resource}}, Converter={StaticResource whereUsedIndicatorTooltipConverter}}" />
Where resource is declared at the top of this page in XAML as:
<UserControl.Resources>
<resources:myResource x:Key="resource" />
</UserControl.Resources>
At runtime I get this exception:
System.Windows.Markup.XamlParseException: Provide value on 'System.Windows.Data.Binding' threw an exception. [Line: 47 Position: 42] ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.....
I'm aware from this StackOverflow question that the ConverterParameter
is not bindable and is not a DependencyObject
. Is there a workaround to this problem, besides putting the text in the XAML?
I found a solution from Brandon Truong. This works very well. I put my FrameworkElement with DependencyProperty converter in:
<UserControl.Resources>
<utilConverters:myTooltipConverter x:Key="myTooltipConverter" Tooltips="{Binding Path=tooltips, Source={StaticResource resource}}" />
</UserControl.Resources>
I got same error here , **
ElementName=RadCalendarMonths,Path=SelectedDate,StringFormat='MMMM yyyy',ConverterCulture={Binding Path=CurrentCultureInfo, Source={StaticResource ResourceWrapper}}}"/>
I used Converter Culture property Binded! Opps! I can't do that because the property ConverterCulture is not a DependencyProperty. If a property is not instance of DependencyProperty you cant use binding on it.
If you look at Property(F4) Pane on VS2010 you can see that some properties support Binding some properties does not! Some properties not seen there because some properties are read only as u know.
So using resource is a logical way to solve it.
精彩评论