문제

I've got the following question: what's the expected scenario for the logic when I would want to bind some elements inside of ViewModel separatly. What I mean... http://slodge.blogspot.co.uk/2013/04/n3-kitten-cells-on-iphone-n1-days-of.html

There is a "Kitten" class in the sample provided - this is just a common "DTO" object. And there is also a modelview class which contains those objects list:

public List<Kitten> Kittens
{
    get ...
    set { ... RaisePropertyChanged(() => Kittens); }
}

We can bind a grid with cells (which bound to Kitten properties). But what if I would want to be able to activate RaisePropertyChanged on every property of Kitten separatly? I.e., if the kitten Title changed, then to call RaisePropertyChanged (and accordingly, change only bound cell value instead of the whole list refreshing) on KittenTitle property (for instance)?

The sample with Kittens is obviously primitive and does not need such implementation, but what if instead of Kittens I would have a list similar to Facebook App menu panel, where there are menu items (amount of which can vary) and those items can have "Notifications Count" label (or can not) so, instead of the complete refresh of the list, how can I initiate that label only refreshing (caused by related property inside the "Kitten" instance changed)? (That looks like viewModel inside viewModel for me, but not sure how to solve it smarter with MvvmCross).

Thank you!

도움이 되었습니까?

해결책

You can implement Nested INotifyPropertyChanged objects - exactly as you do in Windows binding.

So if one Kitten raises its property changed then only that part of the UI for that kitten will refresh

e.g. a Kitten could be written:

public class DynamicKitten : MvxNotifyPropertyChanged // can use MvxViewModel as base class if preferred
{
    private string _name;
    public string Name
    {
        get { return _name; }
        set { _name = value; RaisePropertyChanged(() => Name); }
    }
}

For some examples of this - mostly using Linq to wrap static objects - see:

One of my favorite StackOverflow libraries took this INPC approach all the way back to the Json layer - take a look at all the INPC entities in https://stacky.codeplex.com/SourceControl/latest#trunk/source/Stacky/Entities/Answer.cs

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top