我要綁定在WebView中的事件,但我有例外:事件綁定到MVVM模式在Windows 8
型「
Windows.UI.Xaml.Markup.XamlParseException
」 的異常出現在VK.exe但在用戶沒有處理代碼WinRT的信息:不能 '
Win8nl.Behaviors.EventToCommandBehavior
' 增加collection 型 'System.Collections.ObjectModel.ObservableCollection<WinRtBehaviors.Behavior>
' 的類型的實例
正如你可能知道的,在Windows SDK 中沒有System.Interaction.dll。我試圖在網上找到它(爲Windows RT編譯)或Blend文件夾中,但不能。
比我發現Win8nl它使用行爲,使我可以連接viewmodel控件和RelayCommands的事件。
他們幫我裝綁定事件的看法: 這裏是代碼:
...
xmlns:WinRtBehaviors="using:WinRtBehaviors"
xmlns:Win8nl_Behavior="using:Win8nl.Behaviors"
DataContext="{Binding Login, Source={StaticResource Locator}}">
<WebView x:Name="webView"
Grid.Row="1"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Top"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
Height="420" Width="530">
<WinRtBehaviors:Interaction.Behaviors>
<Win8nl_Behavior:EventToCommandBehavior Event="LoadCompleted"
Command="WebViewLoadedCommand" />
</WinRtBehaviors:Interaction.Behaviors>
</WebView>
視圖模型:
public LoginViewModel(IDataService dataService)
{
WebViewLoadedCommand = new RelayCommand(() => {
var msg = new MessageDialog("Web View Loaded");
msg.ShowAsync();
});
}
public RelayCommand WebViewLoadedCommand { get; private set; }
此外,我想NavigatedEventsArgs參數,就像我在做的WP7 & System.Interaction:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Navigated">
<mvvm:EventToCommand Command="{Binding NavigatedCommand, Mode=OneWay}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
謝謝!