Wpf 将命令绑定到已加载的视图事件

Wpf 将命令绑定到已加载的视图事件,wpf,xaml,commandbinding,Wpf,Xaml,Commandbinding,我试图在视图加载完毕后运行一个方法。我已尝试将命令绑定到视图中的Loaded事件,但它无法运行。引发的内部异常是 “在”System.Windows.Data.Binding“上提供值时引发了异常。” 行号“14”和行位置“14” 如何才能绑定到视图的已加载的事件,以便在视图完成加载后运行某些内容?如果要将命令绑定到已加载的事件,应使用“System.Windows.Interactivity”程序集 <UserControl x:Class="Components.Map.MapVi

我试图在视图加载完毕后运行一个方法。我已尝试将命令绑定到视图中的
Loaded
事件,但它无法运行。引发的内部异常是

“在”System.Windows.Data.Binding“上提供值时引发了异常。” 行号“14”和行位置“14”



如何才能绑定到视图的
已加载的
事件,以便在视图完成加载后运行某些内容?

如果要将命令绑定到
已加载的
事件,应使用“System.Windows.Interactivity”程序集

<UserControl x:Class="Components.Map.MapView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:map="clr-namespace:Components.Map"
             xmlns:controls="clr-namespace:Windows.Controls;assembly=Windows.Controls"
             xmlns:ValidationRules="clr-namespace:Windows.Controls.ValidationRules;assembly=Windows.Controls"
             xmlns:directGraphicsControl="clr-namespace:Windows.DirectGraphicsControl;assembly=Windows.DirectGraphicsControl"
             xmlns:colorBar="clr-namespace:Components.Common.ColorBar;assembly=Components.Common"
             xmlns:RefinedRibbonControls="clr-namespace:Components.Common.Controls.RefinedRibbonControls;assembly=Components.Common"
             xmlns:UserControls="clr-namespace:Components.Common.UserControls;assembly=Components.Common"
             xmlns:map1="clr-namespace:Models.Map;assembly=Models.Map"
             xmlns:utilities="clr-namespace:Windows.Utilities;assembly=Windows.Utilities"
             xmlns:system="clr-namespace:System;assembly=mscorlib"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">

             <i:Interaction.Triggers>
                <i:EventTrigger EventName="Loaded">
                    <i:InvokeCommandAction Command="{Binding LoadedCommand}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>

</UserControl>


System.Windows.Interactivity.dll位于Microsoft Expression Blend软件开发工具包(SDK)()中,也可用作。

+1以秒为单位击败我,尽管我将采用
CallMethodAction
操作路线。感谢您的回答。顺便说一句,不需要下载.dll,因为它已经位于.NET framework程序集中(
..\Microsoft SDK\Expression\Blend\.NETFramework\v4.5\Libraries\System.Windows.Interactivity.dll
)看起来像是“System.Windows.Interactivity”已经开源。结账
<UserControl x:Class="Components.Map.MapView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:map="clr-namespace:Components.Map"
             xmlns:controls="clr-namespace:Windows.Controls;assembly=Windows.Controls"
             xmlns:ValidationRules="clr-namespace:Windows.Controls.ValidationRules;assembly=Windows.Controls"
             xmlns:directGraphicsControl="clr-namespace:Windows.DirectGraphicsControl;assembly=Windows.DirectGraphicsControl"
             xmlns:colorBar="clr-namespace:Components.Common.ColorBar;assembly=Components.Common"
             xmlns:RefinedRibbonControls="clr-namespace:Components.Common.Controls.RefinedRibbonControls;assembly=Components.Common"
             xmlns:UserControls="clr-namespace:Components.Common.UserControls;assembly=Components.Common"
             xmlns:map1="clr-namespace:Models.Map;assembly=Models.Map"
             xmlns:utilities="clr-namespace:Windows.Utilities;assembly=Windows.Utilities"
             xmlns:system="clr-namespace:System;assembly=mscorlib"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity">

             <i:Interaction.Triggers>
                <i:EventTrigger EventName="Loaded">
                    <i:InvokeCommandAction Command="{Binding LoadedCommand}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>

</UserControl>