This is the reason .NET does not use methods to return simple objects, but CLR properties. You're doing it the Java style, not the .NET style.
public string MySource {
get { return "images/" + name + ".png"; }
}
Now the property is exposed, you have some choices :
DataBind your view to itself (in constructor : DataContext = this;
)
< Image source="{Binding MySource}" />
Name your UserControl (or whatever) (<UserControl x:name="this" ...>
)
< Image source="{Binding MySource, ElementName=this}" />
Use relativesource binding
< Image source="{Binding MySource, RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}" />
EDIT :
If I understand well, actually you want to do a binding with a parameter (the name of the image here). You can't. Only Command bindings allows a CommandParameter. You could use many resource declared ObjectDataProviders, or Converters, but that's too much overhead for your simple job.
Your simple solution : use an array for all your images, and one-way bind to the individual objects of this array.
private string[] mysource = new[] {
"images/foo.png",
"images/bar.png",
"images/baz.png"};
public string[] MySource {
get { return mySource; }
}
DataBind your view to itself (in constructor : DataContext = this;
)
< Image source="{Binding MySource[0]}" />
- ...etc.
I did not test it, but the man from the following article did :
http://www.codeproject.com/Articles/37352/WPF-Binding-to-individual-collection-items-but-not.aspx