2024-03-11 05:12:02 +00:00
|
|
|
|
using Prism.Commands;
|
|
|
|
|
|
using Prism.Mvvm;
|
|
|
|
|
|
using Prism.Regions;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace InSituLaboratory.ViewModels.Pages
|
|
|
|
|
|
{
|
|
|
|
|
|
public class ViewModelBase : BindableBase, INavigationAware
|
|
|
|
|
|
{
|
|
|
|
|
|
public string PageTitle { get; set; } = "页面标题";
|
|
|
|
|
|
public bool IsCanClose { get; set; } = true;
|
|
|
|
|
|
|
|
|
|
|
|
public string SearchKey { get; set; }
|
2024-03-15 02:27:50 +00:00
|
|
|
|
public string PrimaryKey { get; set; }
|
2024-03-11 05:12:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DelegateCommand CloseCommand { get; set; }
|
|
|
|
|
|
public DelegateCommand RefreshCommand { get; set; }
|
|
|
|
|
|
public DelegateCommand<object> ModifyCommand { get; set; }
|
|
|
|
|
|
public DelegateCommand<object> DeleteCommand { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
IRegionManager _regionManager;
|
|
|
|
|
|
public ViewModelBase(IRegionManager regionManager)
|
|
|
|
|
|
{
|
|
|
|
|
|
_regionManager = regionManager;
|
|
|
|
|
|
|
|
|
|
|
|
CloseCommand = new DelegateCommand(DoClose);
|
|
|
|
|
|
RefreshCommand = new DelegateCommand(Refresh);
|
|
|
|
|
|
ModifyCommand = new DelegateCommand<object>(DoModify);
|
|
|
|
|
|
DeleteCommand = new DelegateCommand<object>(DoDelete);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DoClose()
|
|
|
|
|
|
{
|
|
|
|
|
|
//拿到主区域,从区域里移除对应的页面,根据页面的名称
|
|
|
|
|
|
var region = _regionManager.Regions["MainRegion"];
|
|
|
|
|
|
var view = region.Views.Where(v => v.GetType().Name == PageName).FirstOrDefault();
|
|
|
|
|
|
if (view != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
region.Remove(view);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void Refresh() { }
|
|
|
|
|
|
public virtual void DoModify(object model) { }
|
|
|
|
|
|
public virtual void DoDelete(object model) { }
|
|
|
|
|
|
private string PageName { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public void OnNavigatedTo(NavigationContext navigationContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
PageName = navigationContext.Uri.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool IsNavigationTarget(NavigationContext navigationContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnNavigatedFrom(NavigationContext navigationContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|