1

I have a static class with certain functions to give path of assets. Currently I am just creating wrapper around those function in all the viewmodels for binding. I was wondering if there was some way in windows phone 8.1 to bind the static function directly to the image source. In wpf Objectdataprovider would have been useful but it is not supported in windows store apps. I was unable to find any documentation as well.

<Rectangle.Fill>
 <ImageBrush Stretch="Fill" 
             ImageSource="{Binding ImagePath"/>
 </Rectangle.Fill>

Thanks in advance

Monil Gandhi
  • 544
  • 1
  • 5
  • 13
  • Can you modify the functions into properties? if so, you can bind to static property like [this](http://stackoverflow.com/questions/936304/binding-to-static-property) – kennyzx Sep 28 '14 at 08:30
  • Tried that before. Getting this error "The type FooBar is abstract and must include an explicit value" I havent converted the class to non static though. – Monil Gandhi Sep 28 '14 at 08:45
  • Is there any particular reason why you're using functions instead of properties? `ImagePath` seems like it should be a property instead of a function. – Decade Moon Sep 28 '14 at 08:52
  • Sure I can use it as a property as well. The problem is binding to static function/property. – Monil Gandhi Sep 28 '14 at 08:56

1 Answers1

1

It's (currently) not possible to bind to a static class as binding requires an object instance. You can, however, bind to static properties of a class.

You create a instance wrapper around your static class:

public class BindingHelper
  {
    public static string ImagePath
    {
      get { return AssetHelper.ImagePath; }
    }
  }

Now create an application resource for this BindingHelper:

<application.resources>
  <BindingHelper x:key="BindingHelperResource"></BindingHelper >
</application.resources>

And use this resource for your Binding:

<textblock text="{Binding Path=ImagePath, Source={StaticResource BindingHelperResource}}">
Postlagerkarte
  • 6,600
  • 5
  • 33
  • 52