卡利Micro和ModernUI例子/教程 [英] Caliburn Micro and ModernUI Examples/Tutorials

查看:385
本文介绍了卡利Micro和ModernUI例子/教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有任何人有关于如何使用ModernUi一起使用微卡利一个例子或教程( https://mui.codeplex.com ) ?

does anyone have an example or tutorial on how to use Caliburn Micro together with ModernUi (https://mui.codeplex.com)?

推荐答案

好了,所以我对与它快速的烂摊子,在梅论坛一看,这似乎是最好的做法:

Ok so I had a quick mess about with it and a look on the Mui forums and this seems to be the best approach:

由于从你需要采取一个观点,第一种方法,然后找到相应的虚拟机并绑定URL中的窗口加载内容的两个

Since the window loads content from URLs you need to take a view-first approach, and then locate the appropriate VM and bind the two.

要做到这一点,最好的办法似乎是通过用来加载内容到 ContentLoader 类> ModernWindow 时,被请求。你可以只继承 DefaultContentLoader 并提供必要的CM魔术结合起来加载的项目:

The best way to do this appears to be via the ContentLoader class which is used to load the content into the ModernWindow when it is requested. You can just subclass DefaultContentLoader and provide the necessary CM magic to bind up loaded items:

public class ModernContentLoader : DefaultContentLoader
{
    protected override object LoadContent(Uri uri)
    {
        var content = base.LoadContent(uri);

        if (content == null)
            return null;

        // Locate the right viewmodel for this view
        var vm = Caliburn.Micro.ViewModelLocator.LocateForView(content);

        if (vm == null)
            return content;

        // Bind it up with CM magic
        if (content is DependencyObject)
        {
            Caliburn.Micro.ViewModelBinder.Bind(vm, content as DependencyObject, null);
        }

        return content;
    }
}

您CM的引导程序应该只启动一个 ModernWindow 视图模型是由 ModernWindow 基于视图(CM尝试使用备份 EnsureWindow 这将创建一个新的基本WPF窗口类,当然,除非你的控制已经从窗口继承其 ModernWindow 一样。如果你需要的所有对话和弹出窗口是MUI你可能需要重新实现窗口管理器):

Your CM bootstrapper should just bootstrap a ModernWindow viewmodel which is backed by a ModernWindow based view (CM tries to use EnsureWindow which creates a new basic WPF Window class, unless of course your control already inherits from Window which ModernWindow does. If you need all dialogs and popups to be MUI you might need to reimplement WindowManager):

public class Bootstrapper : Bootstrapper<ModernWindowViewModel>
{
}



其可以是导体(OneActive),看起来像这样的:

Which can be a conductor (OneActive) and looks like this:

public class ModernWindowViewModel : Conductor<IScreen>.Collection.OneActive
{
}

和XAML的看法是

ModernWindowView.xaml

<mui:ModernWindow x:Class="WpfApplication4.ViewModels.ModernWindowView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mui="http://firstfloorsoftware.com/ModernUI"
                                     Title="ModernWindowView" Height="300" Width="300" ContentLoader="{StaticResource ModernContentLoader}">   
    <mui:ModernWindow.MenuLinkGroups>
        <mui:LinkGroupCollection>
            <mui:LinkGroup GroupName="Hello" DisplayName="Hello">
                <mui:LinkGroup.Links>
                    <mui:Link Source="/ViewModels/ChildView.xaml" DisplayName="Click me"></mui:Link>
                </mui:LinkGroup.Links>
            </mui:LinkGroup>
        </mui:LinkGroupCollection>
    </mui:ModernWindow.MenuLinkGroups>
</mui:ModernWindow>



显然,你需要做的加载器获取资源太:

Obviously you need to make the loader a resource too:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.xaml" />
            <ResourceDictionary Source="/FirstFloor.ModernUI;component/Assets/ModernUI.Dark.xaml"/>
            <ResourceDictionary>
                <framework:ModernContentLoader x:Key="ModernContentLoader"></framework:ModernContentLoader>
                <wpfApplication4:Bootstrapper x:Key="Bootstrapper"></wpfApplication4:Bootstrapper>
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>



这里的 ChildViewModel 我使用的测试:

public class ChildViewModel : Conductor<IScreen>
{
    public void ClickMe()
    {
        MessageBox.Show("Hello");
    }
}

和XAML中为(只是一个按钮)

And the XAML for that (just a button)

<UserControl x:Class="WpfApplication4.ViewModels.ChildView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                     Height="350" Width="525">
    <Grid>
        <StackPanel>
        <TextBlock >Hello World</TextBlock>
        <Button x:Name="ClickMe" Width="140" Height="50">Hello World</Button>
        </StackPanel>
    </Grid>
</UserControl>

和概念证明:

这篇关于卡利Micro和ModernUI例子/教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆