2017-09-04 66 views
-1

我有一個自定義控件,覆蓋了UIScrollView。 呈現兩個UIViews時呈現。一個是PDF,一個是上面的圖層。 上面的圖層包含一組文本,這些文本在pdf上的不同位置呈現。iOS MvvmCross CustomBinding查看

我使用MvvmCross所以有一個模型。文本集合是可觀察的。 如何將可觀察集合綁定到需要在圖層中呈現的結果?

In short...pseudo 

UIScrollViewWrapper 
On draw create two layers 
layer 1 is pdf image 
layer above is view with texts. 

Texts need to be bind and observed by Model.Texts (ObservableCollection<string>) 

我想:

var set = this.CreateBindingSet<ViewWithScrollView, ViewWithScrollViewModel>(); 
set.Bind(ScrollView.LayerView).For(x => x.LayerItems).To(vm => vm.LayerItems); 
set.Apply(); 

的LayerView是MvxView對的BindingContext

+0

你的問題不清楚。你能分享更多的代碼嗎? –

+0

我發現了一個我將發佈的工作解決方案,我還會嘗試使用簡單的圖像更清晰地表達我的問題。更新將很快推出! PS。對於downvoter,只寫一個評論,如科爾而不是單獨downvote ... –

回答

1

好的解決方案

的自己實現滾動視圖的將是:

public class MyOwnScrollView : UIScrollView, IUIScrollViewDelegate, IMvxBindable 
{ 
    //Implement the IMvxBindable 
    //Add property BindingContext 
    public IMvxBindingContext BindingContext { get; set; } 

    //Property for holding the datacontext 
    [MvxSetToNullAfterBinding] 
    public object DataContext 
    { 
     get { return BindingContext.DataContext; } 
     set { BindingContext.DataContext = value; } 
    } 

    public MyOwnScrollView() 
    { 
     //Call Mvx for creating the bindingcontext 
     this.CreateBindingContext() 
    } 

    //Create something where you can create the set voor fluent binding with the view model. For example 
    public void MyBindingToCreate() 
    { 
     var set = new new MvxFluentBindingDescriptionSet<AViewInMyScrollView, MyViewViewModel>(AViewInMyScrollView); //Because CreateBindingSet is part of MvxView and UIScrollView is not MvxView 
     set.Bind(AViewInMyScrollView).For(x => x.MyPropertyOfView).To(vm => vm.PropertyOfViewModel); 
     set.Apply(); 
} 

和您正在使用ScrollView的地方將綁定到datacontext

public partial class MyView : MvxView 
{ 
    public MyView() : base("MyView", null) 
    { 

    } 

    public override void ViewDidLoad() 
    { 
     base.ViewDidLoad(); 

     var set = this.CreateBindingSet<MyView, MyViewViewModel>(); 
     set.Bind(MyOwnScrollView).For(s => s.DataContext).To(vm => vm); 
     set.Apply(); 
    } 
} 

PS。我將通過自己的控制在MvvmCross中執行此操作。 但是,這可以用於所有自己的控件!