2017-09-04 7 views
-1

私はUIScrollViewのオーバーライドをカスタムコントロールしています。 レンダリング時に2つのUIViewがレンダリングされます。 1つはPDFであり、1つは上のレイヤーです。 上記のレイヤーには、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

私が掲載する作業の解決策を見つけたので、簡単なイメージで私の質問をより明確にするよう努力します。更新はすぐに続きます! Ps。 downvoterのためだけに、downvoteの代わりにColeのようなコメントを書いてください... –

答えて

1

[OK]を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で独自のコントロールで実装します。 ただし、これはすべてのコントロールに使用できます。

関連する問題