c# - Image Binding to string -


I am unable to display the image that is in this resource / images / abc.png

What I'm doing here:

  public class A {personal string image; Public string image {{return image; } Set {if (value! = This.image) {image = value; }}}}  

In my CS file:

  if (some condition) {a.image = @ "Resources / Images / abc.png" ; }  

In my xml file:

  & gt; Datamapplet X: Key = "ThemeDatabase" & gt; & Lt; Image Stretch = "None" grid. Rows = "1" source = "{binding image}" /> & Lt; / DataTemplate & gt;  

But do not display its image, how to fix it? Am I doing wrong here?

Your image path should be fine, provided that there is actually a file named abc in the named folder

The resource is set to (which is the default).

Update I'm not sure that the above is also true for Windows Phone. I think the default conversion of the ImgSource from String can not be enabled on that platform because it is in WPF.


However, if you want to change the image, during the runtime on any platform property, you need to implement a property change mechanism Indicates the binding that the image property has changed in one way to implement the interface in your class A:

  public class A: INotifyPropertyChanged {public event PropertyChangedEventHandler PropertyChanged; Private string image; Public string image {{return image; } Set {image = value; RaisePropertyChanged ("Image"); }} Protected Zero RaisePropertyChanged (string propertyName) {var property changed = property changed; If (propertyChanged! = Null) {propertyChanged (this, New PropertyChangedEventArgs (propertyName)); It is also important that the  image  binding is set correctly, that is,  DataContext  templated items Sets a reference for an example of class A. 


Comments