Dynamic Binding UIWebView in MVVMCross

后端 未结 1 1320
难免孤独
难免孤独 2021-01-16 03:19

I\'m trying to make a change to sample project Cirrious.Conference. In particular in the Touch View at SessionView class and at this class

https://github.com/slodge/

1条回答
  •  清酒与你
    2021-01-16 03:55

    Since UIWebView doesn't expose a property for the LoadRequest, then you can't bind directly to it.

    If you want to use binding for LoadRequest, then 3 options available to you are:

    1. Inherit MyWebView from UIWebView, add a C# property that drives LoadRequest and then use that class in your UI and that property in your Swiss binding - e.g.:

          [Register("MyWebView")]
          public class MyWebView : UIWebView
          {
              public MyWebView()
              {
              }
      
              public MyWebView(IntPtr handle) : base(handle)
              {
              }
      
              private string _myUrl;
              public string MyUrl
              {
                  get { return _myUrl; }
                  set
                  {
                     if (_myUrl == value) return;
                     _myUrl = value;
                     LoadRequest(value); // or similar (I've not checked the syntax!)
                  }
              }
          }
      
    2. Implement a custom target Swiss binding and add it to your Setup.cs. The process for this is described in this Custom Bindings presentation - which also includes links to some examples (one of them is in the Conference app)

    3. If this property will never change, then don't use binding and instead just call LoadRequest in your MvxViewController ViewDidLoad - e.g.

           public void ViewDidLoad()
           {
               base.ViewDidLoad();
      
               var myViewModel = (MyViewModel)ViewModel;
               var url = myViewModel.Url;
               TheWebView.LoadRequest(url);
           }
      

    0 讨论(0)
提交回复
热议问题