码迷,mamicode.com
首页 > Windows程序 > 详细

PopupWindowAction breaking MEF import?

时间:2015-02-26 13:27:42      阅读:190      评论:0      收藏:0      [点我收藏+]

标签:

If you use Prism InteractionRequest.PopupWindowAction feature, you might have found the MEF Import attribute does not work in the popup window.

This is because PopupWindowAction.WindowContent property creates a new instance of your xaml usercontrol which caused the conflit to MEF principal and consequently the Import chain is broken here.

My workaround is not to use xaml code for the interaction which may look like this:

<i:Interaction.Triggers>
        <prism:InteractionRequestTrigger SourceObject="{Binding BizSelectionRequest, Mode=OneWay}">
            <PopupWindowAction CenterOverAssociatedObject="True"
                                              IsModal="True">
                <PopupWindowAction.WindowContent>
                    <views:BizSearch />
                </PopupWindowAction.WindowContent>
            </PopupWindowAction>
        </prism:InteractionRequestTrigger>
    </i:Interaction.Triggers>

Instead, you can comment the above xaml code and create the expected interaction in your code behind:

                var triggerCollection = System.Windows.Interactivity.Interaction.GetTriggers(this);
                InteractionRequestTrigger trigger = new InteractionRequestTrigger();
                var binding = new Binding(“BizSearchRequest");
                binding.Source = this.DataContext;
                BindingOperations.SetBinding(trigger, InteractionRequestTrigger.SourceObjectProperty, binding);
                PopupWindowAction pwa = new PopupWindowAction();
                pwa.WindowContent = v;
                pwa.WindowContent.DataContext = vm;
                pa.CenterOverAssociatedObject = true;
                pa.IsModal = true;
                trigger.Actions.Add(pa);
                triggerCollection.Add(trigger);

The "v" and "vm" are imported by MEF

[Import]
BizSearchPopup bizSearchPopup;

[Import]
BizSearchPopupViewModel bizSearchPopupViewModel;

By this trick, a little dirty though, whatever you import within your BizSearchPopup or BizSearchPopupViewModel should work.

 

PopupWindowAction breaking MEF import?

标签:

原文地址:http://www.cnblogs.com/dfun/p/4301036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!