将mvvm light Relaycommand绑定到页面加载事件

将mvvm light Relaycommand绑定到页面加载事件,mvvm,windows-phone-8.1,mvvm-light,Mvvm,Windows Phone 8.1,Mvvm Light,我正在开发Windows phone 8.1。 我有一个RelayCommand命令,它执行一些异步方法。 我想知道如何将页面加载事件从页面绑定到视图模型中的RelayCommand 我看到的所有示例都是将RelayCommand绑定到按钮 如何将其绑定到页面加载事件?我看到一些示例使用EventToCommand。但是我使用的是Windows phone 8.1,我不认为我有我看到的一些文章中提到的行为方面的东西。请确保在参考资料中添加行为扩展 然后定义事件触发器调用命令: <Page

我正在开发Windows phone 8.1。 我有一个RelayCommand命令,它执行一些异步方法。 我想知道如何将页面加载事件从页面绑定到视图模型中的RelayCommand

我看到的所有示例都是将RelayCommand绑定到按钮


如何将其绑定到页面加载事件?我看到一些示例使用EventToCommand。但是我使用的是Windows phone 8.1,我不认为我有我看到的一些文章中提到的行为方面的东西。

请确保在参考资料中添加行为扩展

然后定义事件触发器调用命令:

<Page
    x:Class="App31.PivotPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:App31"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:data="using:App31.Data"
    xmlns:i="using:Microsoft.Xaml.Interactivity"
    xmlns:core="using:Microsoft.Xaml.Interactions.Core"
    mc:Ignorable="d">
    <i:Interaction.Behaviors>
        <core:EventTriggerBehavior EventName="Loaded">
            <core:InvokeCommandAction Command="{Binding MyCommandInTheViewModel}" />
        </core:EventTriggerBehavior>
    </i:Interaction.Behaviors>
//....
//.. rest of page code

//....
//.. 页面代码的其余部分
其中,
mycommandtheviewmodel
是虚拟机中的命令,页面的
DataContext
设置为虚拟机