mainwindow.xml.cs
public partial class MainWindow : MetroWindow { private readonly IRegionManager regionManager; public MainWindow(IRegionManager regionManager) { InitializeComponent(); this.regionManager = regionManager; } private void Button_Click(object sender, RoutedEventArgs e) { regionManager.RequestNavigate("ContentRegion", nameof(DefaultView)); } private void MetroWindow_Loaded(object sender, RoutedEventArgs e) { regionManager.RequestNavigate("ContentRegion", nameof(DefaultView)); } }
app.xml.cs
public partial class App { protected override Window CreateShell() { return Container.Resolve<MainWindow>(); } protected override void RegisterTypes(IContainerRegistry containerRegistry) { containerRegistry.RegisterSingleton<AppDbContext>(sp => { var options = new DbContextOptionsBuilder<AppDbContext>() .UseSqlServer("Server=127.0.0.1;Database=db1;User Id=sa;Password=123456;") .Options; return new AppDbContext(options); }); containerRegistry.RegisterForNavigation<DefaultView>(); } }
标签:containerRegistry,regionManager,mvvm,void,private,prism,partial,wpf,public From: https://www.cnblogs.com/zyip/p/18664350