【发布时间】:2016-08-02 07:22:04
【问题描述】:
我的应用有一个用于显示一些联系信息的 WebView。它有一个指向我想使用Device.OpenUri() 从外部加载的网站的链接。我正在使用FreshMvvm,我想从 ViewModel 中的 WebView 拦截 Navigating 事件并取消将外部页面加载到 WebView 中的默认操作。
我尝试过使用 Corcav.Behaviors 插件,它确实调用了我的 ViewModel 命令:
<WebView
HorizontalOptions="Fill"
VerticalOptions="FillAndExpand"
Source="{Binding WebViewSource}">
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand
EventName="Navigating"
Command="{Binding NavigatingCommand}"
CommandParameter="{Binding}"/> <!-- what goes here -->
</b:BehaviorCollection>
</b:Interaction.Behaviors>
</WebView>
但我不确定 CommandParameter 应该是什么 - 我需要被点击的链接的 URI,但我不知道如何防止发生默认行为。
这是最好的方法还是我应该寻找替代方法?
【问题讨论】:
-
不需要指定CommandParameter,NavigatingCommand应该是DelegateCommand
类型,tappedItem是参数的item属性。 -
@rauland 当我使用这种方法时,即省略 CommandParameter,我没有得到任何作为参数传递的信息 - 即使将
object指定为参数类型。