Is data binding to a method possible in Silverlight?

We have a dynamic flooring system that does not use regular resource files; selection of resources from the database through the library of the language manager. Based on an outdated solution (VB6), it controls the languages ​​according to the resource name in the control tag property. After initializing the page, we run the method that takes LayoutRoot and returns it to the children using the lines that are viewed from the tag, where the control has one. This turns out to be cumbersome, a recursive routine has turned into a monster to cater for the intricacies of various controls, and I want to switch to using data binding to apply strings instead.

I understand that I can declare properties for binding for each control, but this will be associated with a lot of code, and I hope that there is a better way. Is there a way to bind to a method by passing a parameter. I guess a method similar to this.

public string GetResource(string resourceName) { string resource = <fetch resource from language manager>; if (String.IsNullOrEmpty(resource)) { return resourceName; } else { return resource; } } 

We already have a static method in our application for this search, which has the following signature.

 public static Resource(string resourceName, string defaultValue) 

Being able to use this directly would be great.

+7
c # data-binding silverlight
source share
1 answer

You can use a value converter , and then pass a parameter to search for resources. It would not have to matter which property was bound, since your value converter could ignore this part and simply use the passed ConverterParameter to execute your resource.

Then you can create an instance of your resource converter in application resources and use it throughout the application.

 ... SomeProperty="{Binding Converter={StaticResource MyAppResourceConverter}, ConverterParameter=SomePropertyResourceName}}" ... 
+4
source share

All Articles