Bind command to Loaded event of view

前端 未结 1 955
滥情空心
滥情空心 2020-12-14 16:24

I am trying to get a method to run when a view has finished loading. I have tried to bind a command to the Loaded event in the view but it fails to run. The inn

相关标签:
1条回答
  • 2020-12-14 16:57

    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.

    0 讨论(0)
提交回复
热议问题