Exemple #1
0
    public static ModelViewModelCollectionBinding BindToViewCollection <TCollectionType>(this ViewBase view,
                                                                                         ModelCollection <TCollectionType> viewModelCollection, Func <ViewModel,
                                                                                                                                                      ViewBase> createView,
                                                                                         Action <ViewBase> added,
                                                                                         Action <ViewBase> removed,
                                                                                         Transform parent,
                                                                                         bool viewFirst = false)
    {
        var binding = new ModelViewModelCollectionBinding()
        {
            SourceView            = view,
            ModelPropertySelector = () => viewModelCollection
        };

        binding.SetParent(parent);
        binding.SetAddHandler(added);
        binding.SetRemoveHandler(removed);
        binding.SetCreateHandler(createView);
        if (viewFirst)
        {
            binding.ViewFirst();
        }
        view.AddBinding(binding);
        binding.Bind();

        return(binding);
    }
Exemple #2
0
    public static ModelViewModelCollectionBinding BindToViewCollection <TView, TViewModelType>(
        this ViewBase view,
        Func <ModelCollection <TViewModelType> > sourceViewModelCollection,
        ICollection <TView> viewCollection, bool viewFirst = false
        )
        where TView : ViewBase
        where TViewModelType : ViewModel
    {
        var binding = new ModelViewModelCollectionBinding()
        {
            SourceView            = view,
            ModelPropertySelector = () => sourceViewModelCollection() as IObservableProperty
        }
        .SetAddHandler(v => viewCollection.Add(v as TView))
        .SetRemoveHandler(v => viewCollection.Remove(v as TView));

        if (viewFirst)
        {
            binding.ViewFirst();
        }
        view.AddBinding(binding);
        binding.Bind();
        return(binding);
    }