2017-09-04 3 views
-1

사용자 정의 컨트롤이 있으며 UIScrollView를 재정의합니다. 두 개의 UIView를 렌더링 할 때 렌더링됩니다. 하나는 PDF이고, 하나는 위의 계층입니다. 위의 레이어에는 pdf에서 다른 위치에 렌더링 된 텍스트 모음이 포함되어 있습니다.iOS MvvmCross보기의 사용자 정의 바인딩

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가있는 ScrollView의 자신의 구현이 될 것입니다

+0

질문이 명확하지 않습니다. 그리고 시도한 코드를 더 공유 할 수 있습니까? –

+0

나는 게시 할 작업 솔루션을 발견했으며 간단한 이미지로 내 질문을 더욱 명확하게하려고 노력할 것입니다. 업데이트가 곧 완료 될 예정입니다. 추신. downvoter를 위해서, 단지 downvote 대신에 Cole과 같은 코멘트를 써라. –

답변

1

확인 BindingContext를 해결

에 대한 MvxView입니다 :

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에서 자체 제어로 구현할 것이다. 그러나 이것은 모든 컨트롤에 사용할 수 있습니다!