4

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!

Stuart
  • 66,722
  • 7
  • 114
  • 165
Agat
  • 4,577
  • 2
  • 34
  • 62

1 Answers1

3

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

Stuart
  • 66,722
  • 7
  • 114
  • 165
  • Or you mean to bind "Kitten" object directly to the view (which I've created for that object (for instance, tablecell)) additionally to KittenTitle binding? – Agat Jun 05 '13 at 12:47
  • Sorry, missed the editting of the answer. What I am actually asking, how should the binding go exactly in such scenario. As long as I bind "Kittens" collection first and then "Kitten.Title", but MvxNotifyPropertyChanged will be called on "Kitten". Should I add some more bindings for it (to the view I've created based on "Kitten") or that must be enough? – Agat Jun 05 '13 at 12:58
  • try it - you'll soon get the hang of it :) – Stuart Jun 05 '13 at 13:10
  • Actually, right before bumped into DelayBinging(() => { CreateBindingSet() }) he he Thanks a lot for the fast answering! – Agat Jun 05 '13 at 13:14