2013-06-05 34 views
0

我的XAML:的ImageSource不會改變

<Button Click="LikePost" BorderThickness="0" > 
    <Image Stretch="Uniform" Source="{Binding imagesource}" /> 
</Button> 

設置ImageSource的首次按預期工作,但每當我在我的代碼更新源字符串XAML不更新,是的,我已經包括INotifyPropertyChanghed :

public class Item : INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 

    private string _imagesource; 
    public string imagesource 
    { 
     get { return _imagesource; } 
     set 
     { 
      if (_imagesource == value) return; 
      _imagesource = value; 
      NotifyLikeImageChanged("like"); 
     } 
    } 
    private void NotifyLikeImageChanged(string propertyName) 
    { 
     PropertyChangedEventHandler handler = PropertyChanged; 
     if (PropertyChanged != null) 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
    } 
} 

我在做什麼錯了?

回答

5

但是你發送了錯誤的屬性名,更改此:

NotifyLikeImageChanged("like"); 

這樣:

NotifyLikeImageChanged("imagesource"); 
+0

這麼蠢...:P謝謝! –

+0

@PhilippeMaes,不要叫你自己愚蠢的我的朋友,這只是你碰巧錯過的事情,它發生在我們所有人身上,而且往往我們離項目太近,無法看到它。 –