Bind command to Loaded event of view

If you want to bind command to the Loaded event, you should use the “System.Windows.Interactivity” assembly.

<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 is in Microsoft Expression Blend Software Development Kit (SDK) (download link) and also available as a NuGet package.

Leave a Comment