简体   繁体   English

带有Caliburn.Micro的ModalContentPresenter

[英]ModalContentPresenter with Caliburn.Micro

I am trying to find ways to properly show non-window based modal dialogs (ie. they cover existing part of the window and are shown on top of that content in a modal way - the covered part is not accessible). 我正在尝试找到正确显示基于非窗口的模态对话框的方法(即它们覆盖了窗口的现有部分,并以模态方式显示在该内容的顶部-覆盖的部分无法访问)。 The application is built in .net 4.5 on top of the caliburn.micro framework 1.5.2 and uses MefBootstrapper (based on http://caliburnmicro.codeplex.com/wikipage?title=Customizing%20The%20Bootstrapper ). 该应用程序在caliburn.micro框架1.5.2之上的.net 4.5中构建,并使用MefBootstrapper(基于http://caliburnmicro.codeplex.com/wikipage?title=Customizing%20The%20Bootstrapper )。

The simple solution (overlapping controls in the xaml stack) does not cover all issues, like keyboard focus and navigation. 简单的解决方案(xaml堆栈中的控件重叠)不能涵盖所有问题,例如键盘焦点和导航。

I have found the ModalContentPresenter class, derived from FrameworkElement, and presented at http://programmingwithpassion.wordpress.com/2012/07/01/displaying-modal-content-in-wpf/ which seems to handle most of the possible issues with modal dialogs. 我发现了从FrameworkElement派生的ModalContentPresenter类,并在http://programmingwithpassion.wordpress.com/2012/07/01/displaying-modal-content-in-wpf/中进行了介绍,该类似乎可以解决大多数可能的问题模态对话框。

Unfortunately, the window does not show any content. 不幸的是,该窗口未显示任何内容。 Based on my research it seems like the code conventions are not working for controls defined as children of the ModalContentPresenter. 根据我的研究,似乎代码约定不适用于定义为ModalContentPresenter子级的控件。 Unfortunately, I failed to find the right place to look in the caliburn.micro source code and/or documentation. 不幸的是,我未能在caliburn.micro源代码和/或文档中找到合适的位置。

Example (without ModelContentPresenter, working): 示例(没有ModelContentPresenter,正在运行):

<Window>
    <TextBlock x:Name="SomeName"/>
</Window>

Example (with ModelContentPresenter, not working): 示例(使用ModelContentPresenter,不起作用):

<Window>
    <c:ModelContentPresenter isModal="False">
        <TextBlock x:Name="SomeName"/>
    </c:ModelContentPresenter>
</Window>

What I need to do to get the code conventions working with the ModelContentPresenter, or do you have a better solution? 我需要做什么才能使代码约定与ModelContentPresenter一起使用,还是您有更好的解决方案?

The following code will work. 以下代码将起作用。 It's a slightly modified version of the sample code found at http://caliburnmicro.codeplex.com/discussions/432271 . 它是在http://caliburnmicro.codeplex.com/discussions/432271上找到的示例代码的略微修改版本。

        BindingScope.AddChildResolver(
            type => type == typeof(System.Windows.Controls.ContentPresenter),
            control =>
            {
                var result = new List<DependencyObject>();

                var typedControl = control as System.Windows.Controls.ContentPresenter;
                if (typedControl != null)
                {
                    if (typedControl.Content is DependencyObject)
                    {
                        result.Add(typedControl.Content as DependencyObject);
                    }
                }

                return result;
            });

Note: The ModalContentPresenter is somehow understood by the current Caliburn.Micro's FindNamedDescendants (called as part of the GetNamedElements func, which Sniffer pointed me to). 注意:当前的Caliburn.Micro的FindNamedDescendants(称为GetNamedElements函数的一部分,Sniffer指向我)对ModalContentPresenter有所了解。 As a result, the ModalContentPresenter could not be cought by this way, but its Content and ModalContent property can; 结果,无法通过这种方式找到ModalContentPresenter,但是可以使用它的Content和ModalContent属性。 that's why the test is agains the ContentPresenter type. 这就是为什么测试再次使用ContentPresenter类型的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM