开发者

IoC and Design Time

开发者 https://www.devze.com 2022-12-27 16:23 出处:网络
I have a WPF application which I am using to learn MVVM and IoC. The problem is that the Model used by one of the Views expects to pull one of its dependancies in the constructor from an IoC containe

I have a WPF application which I am using to learn MVVM and IoC.

The problem is that the Model used by one of the Views expects to pull one of its dependancies in the constructor from an IoC container.

When working on this View in the Visual Studio designer it cannot show the design because an exception is being raised in the model.

Is there a way around this? Am I pulling my dependancies in the wrong place in code or is there a way I can pass in constructed dependancies, perhaps through Constructor injectio开发者_Python百科n.

At present the IoC container is setup in code in App.xaml.cs.

The IoC container is a roll-your-own taken from this article on MSDN - http://msdn.microsoft.com/en-us/magazine/cc337885.aspx


I was facing a similar problem recently. I worked around it with the following check:

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            Init();
    }


I found the problem was caused by declaring the ViewModel as the View's datacontext within the Xaml, by moving this to the View constructor the Xaml renders properly in the designer.

0

精彩评论

暂无评论...
验证码 换一张
取 消