小编Ahm*_*oud的帖子

如何使用mvvm在ModernWindow中正确加载内容

在我们公司,我们习惯使用WinForms开发应用程序,现在我们决定使用Caliburn.Micro和Modern UI切换到WPF-MVVM.我们想要达到的目标是拥有一个小应用程序: - 1个现代窗口 - 现代窗口内的2个页面的目标是在该页面内有一个按钮,用于将现代窗口导航到带参数的第二个页面.

我一直在努力了解如何解决这个问题,我成功地使用了Window(没有MUI),但是当谈到MUI时,它并没有真正给我我想要的结果.

到目前为止,我所做的一切都是

  1. 创建一个新的MUI项目
  2. 将Caliburn.Micro添加到项目中
  3. 将App.xaml更改为

    <Application x:Class="MuiWithCaliburn01.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:MuiWithCaliburn01">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <local:AppBootstrapper x:Key="bootstrapper" />
                    <local:ModernContentLoader x:Key="ModernContentLoader" />
                </ResourceDictionary>
                <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
                <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Light.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    
    Run Code Online (Sandbox Code Playgroud)

  4. 创建Bootstrapper类

    
    public class AppBootstrapper : BootstrapperBase
    {
        static AppBootstrapper()
        {
        }
        public AppBootstrapper()
        {
            Initialize();
        }
        protected override void OnStartup(object sender, StartupEventArgs e)
        {
            DisplayRootViewFor();
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  5. 创建ModernContentLoader类

    
    public class ModernContentLoader : DefaultContentLoader
    {
        protected override object LoadContent(Uri uri)
        {
            var content = base.LoadContent(uri);
            if …
    Run Code Online (Sandbox Code Playgroud)

c# wpf mvvm caliburn.micro modern-ui

8
推荐指数
1
解决办法
742
查看次数

标签 统计

c# ×1

caliburn.micro ×1

modern-ui ×1

mvvm ×1

wpf ×1