Image source not updating in listview after property updated in observablecollection

ChrisVardonChrisVardon GBMember ✭✭

I'm databinding an observablecollection to a listview, and inside a viewcell I have an image, binding the source to a property of the collection items using a converter.
Source="{Binding Status, Converter={StaticResource StatusToImageConverter}}"

This does the job when the page loads, but when the item is clicked, I update the status on the item clicked and expect the image to change, however it doesn't and it doesn't hit the converter either.

I have checked that the item is updated which it does, I then call OnPropertyChanged("MyObservableCollection"); but still nothing. If I go back to the previous page and then return, it has updated then.

Any ideas what I'm doing wrong?

Best Answer

  • AlessandroCaliaroAlessandroCaliaro IT ✭✭✭✭✭
    Accepted Answer

    I think you have to implement INPC also in MyModel otherwise when you change Status I think you don't receive the change

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    You should post some code... your Model...

  • ChrisVardonChrisVardon GBMember ✭✭

    @AlessandroCaliaro

    public event PropertyChangedEventHandler PropertyChanged;

    protected void OnPropertyChanged(string name) { PropertyChangedEventHandler handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(name)); } }

    private ObservableCollection<MyModel> _myObservableCollection; public ObservableCollection<MyModel> MyObservableCollection { get { return _myObservableCollection; } set { if (_profiles != value) { _myObservableCollection = value; OnPropertyChanged("MyObservableCollection"); } } }

    private async void ConnectionAvailableTapped(object item)
            {
        var oMyItem = (MyModel)item;
    
    oMyItem .Status = Mystring;
    
        OnPropertyChanged("MyObservableCollection");
    }
    
  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    MyModel?

  • ChrisVardonChrisVardon GBMember ✭✭

    @AlessandroCaliaro The code above is from the viewmodel, and MyModel is basically the model used for each item. My observablecollection is a collection of Mymodel, where mymodel just has some properties

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    Yes but I think your Model should have INPC

  • ChrisVardonChrisVardon GBMember ✭✭
    edited March 2017
    public class MyModel
        {
    
            public string Status
            {
                get;
                set;
            }
    
            public string AccountId
            {
                get;
                set;
            }
    }
    

    @AlessandroCaliaro

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    Accepted Answer

    I think you have to implement INPC also in MyModel otherwise when you change Status I think you don't receive the change

  • ChrisVardonChrisVardon GBMember ✭✭

    Thank you @AlessandroCaliaro . You absolute legend!

  • AshokAshAshokAsh USMember ✭✭

    INPC means?

  • ChrisVardonChrisVardon GBMember ✭✭

    @Ashokkumaar INPC - INotifyPropertyChanged

  • AshokAshAshokAsh USMember ✭✭
    edited August 2017

    this is my model my list updates when I delete items, but not updating when I change the image source inside listeview

    In this I have to change the favicon property

  • ChrisVardonChrisVardon GBMember ✭✭

    @Ashokkumaar you need to inherit from INotifyPropertyChanged on the CategoryModel also, then call the OnPropertyChanged on the set in the image url property.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    I suggest to use PropertyChanged.Fody
  • AshokAshAshokAsh USMember ✭✭

    is it possible to achieve this with out using any plugin?

Sign In or Register to comment.