在MVVMCross动态绑定的UIWebView [英] Dynamic Binding UIWebView in MVVMCross
问题描述
我试图做出改变,以示例项目Cirrious.Conference。特别是在SessionView类触摸查看,并在这个类
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
<一个href=\"https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.Core/ViewModels/SessionLists/BaseSessionListViewModel.cs\" rel=\"nofollow\">https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.Core/ViewModels/SessionLists/BaseSessionListViewModel.cs
在法
protected void NavigateToSession(Session session)
{
ShowViewModel<SessionViewModel>(new { key = session.Key });
}
我想去除隐藏一个UIWebView(在app)带班会议的一个属性的loadRequest结合(假设有一个房产网址...)。我已经创造了SessionView一个UIWebView对象,但它不可能创造一个Swisse绑定...也许这是可能的一个customBinding ...
I'd like to openl a UIWebView (in app) binding LoadRequest with a property of class Session (suppose to have a Property URL...). I have created a UIWebView object in the SessionView but it's not possible to create a Swisse Binding...Maybe it's possible with a customBinding...
我怎么可能会做呢?
推荐答案
由于的UIWebView
不公开为的loadRequest $属性C $ C>,那么你就不能直接绑定到它。
Since UIWebView
doesn't expose a property for the LoadRequest
, then you can't bind directly to it.
如果你想使用绑定的的loadRequest
,然后3个选项提供给您的:
If you want to use binding for LoadRequest
, then 3 options available to you are:
-
继承
MyWebView
从的UIWebView
,添加一个驱动器C#属性的loadRequest
,然后使用您的UI类,并在瑞士的绑定属性 - 例如:
Inherit
MyWebView
fromUIWebView
, add a C# property that drivesLoadRequest
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!)
}
}
}
实现自定义目标结合瑞士并将其添加到您的Setup.cs。其中还包括对一些实施例的联系(其中之一是在会议 - 此该方法是在此自定义绑定的presentation描述应用程序)
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)
如果这个属性不会改变,那么就不要使用绑定,而是只需调用中的loadRequest你的 MvxViewController
viewDidLoad中 - 例如
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);
}
这篇关于在MVVMCross动态绑定的UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!