WPF打开另外窗体

//======================================================================================
#region 物件替换窗体
        public RelayCommand _MaterialCreate { set; get; }
        public RelayCommand MaterialCreate
        {
            get
            {
                return _MaterialCreate ?? (_MaterialCreate = new RelayCommand(frmCreateMaterial));
            }
        }
        public void frmCreateMaterial()
        {
            //material_sn_replaceView frm = new material_sn_replaceView();
            //frm.ShowDialog();
            Type autoScanInterface = Type.GetType("Midea.MES.Plugin.OnlineRepair.View.material_sn_replaceView,Midea.MES.Plugin.OnlineRepair");
            material_sn_replaceView borrowMachineCtl = Activator.CreateInstance(autoScanInterface, false) as material_sn_replaceView;
            //borrowMachineCtl.Framework = this.Framework;
            var vm = borrowMachineCtl.DataContext as ViewModelPlugin;
            //vm.Framework = this.Framework;

            borrowMachineWin = new Window();
            // 设置全屏
            borrowMachineWin.WindowState = System.Windows.WindowState.Normal;
            borrowMachineWin.WindowStyle = System.Windows.WindowStyle.ToolWindow;
            borrowMachineWin.ResizeMode = System.Windows.ResizeMode.NoResize;
            //borrowMachineWin.Topmost = true;

            borrowMachineWin.Left = 0.0;
            borrowMachineWin.Top = 0.0;
            borrowMachineWin.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
            borrowMachineWin.Height = System.Windows.SystemParameters.PrimaryScreenHeight;

            var grid = new Grid();
            grid.Children.Add(borrowMachineCtl);
            borrowMachineWin.Content = grid;
            borrowMachineCtl.init(this);
            vm.OnLoad(this.Framework);
            borrowMachineWin.ShowDialog();

        }

        #endregion



//xaml文件 关闭按钮
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Shapes;

namespace APP.Plugin.OnlineRepair.View
{
    /// <summary>
    /// material_sn_replaceView.xaml 的交互逻辑
    /// </summary>
    public partial class material_sn_replaceView : MControlBase
    {
        OnlineRepairVM Win = new OnlineRepairVM(); 
             
        public material_sn_replaceView()
        {
            InitializeComponent();
            this.DataContext = new material_sn_replaceVM();
        }


        private void Input_BarCode_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyboardDevice.Modifiers == ModifierKeys.None && e.Key == Key.Enter)
            {
                var p = Input_BarCode.GetBindingExpression(TextBox.TextProperty);
                if (p != null)
                    p.UpdateSource();

                Input_BarCode.Text = string.Empty;                   
                e.Handled = true;
            }
        }

        private void Restart_Click(object sender, RoutedEventArgs e)
        {
            Input_BarCode.Text = string.Empty;
            Input_BarCode.Focus();
        }

        private void MControlBase_Loaded(object sender, RoutedEventArgs e)
        {
            Input_BarCode.Focus();
        }

        //释放窗体
        private void Click_Close(object sender, RoutedEventArgs e)
        {
            Win.RemoveWin();
        }

        public void init(OnlineRepairVM win)
        {
            Win = win;

        }

    }

}


你可能感兴趣的:(return,public,窗体)