WPF MVVM应用 Loaded实现

  1. 引入System.Windows.Interactivity/MicrosoftExpressionInteractions
  2. View.xaml实现

       

<Window  x:Class="WPFSale.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:prism="http://prismlibrary.com/"
        prism:ViewModelLocator.AutoWireViewModel="True"
        xmlns:Ui="clr-namespace:Hm.UI;assembly=Hm.UI"
         
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        mc:Ignorable="d" Title="MainWindow">
    
<!--主要代码实现-->
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded" >
            <ei:CallMethodAction MethodName="View_Loaded" TargetObject="{Binding}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>  
    

  
</Window>
  1. ViewModel.cs主要代码
using Prism.Mvvm;
using SqlHelp;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Windows.Controls;

namespace WPFSale.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {

        public void View_Loaded(object sender,EventArgs e)
        {
          // do something here!


        }

    }
}

猜你喜欢

转载自blog.csdn.net/cxb2011/article/details/89485284
今日推荐