0

私はmvvm-lightWP8アプリケーションに使用しています。

エラーが発生し続けIXXXXX is already registeredます。このソリューションを使用すると、http://developingux.com/2012/06/10/how-to-fix-error-design-time-data-in-blend-with-mvvm-ライト/

エラーは消えましたが、Visual Studio と Blend のどちらにもデザイン データが表示されません。

私のview-model-locator(IContentServiceエラーを発生させず、のみIFeedAPI):

    public class ViewModelLocator
{
    public ViewModelLocator()
    {
        ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

        if (ViewModelBase.IsInDesignModeStatic)
        {
            if (SimpleIoc.Default.IsRegistered<IFeedAPI>())
            {
                SimpleIoc.Default.Unregister<IFeedAPI>();
            }

            SimpleIoc.Default.Register<IFeedAPI, DesignData.DesignFeedAPI>();

            SimpleIoc.Default.Register<IContentService, DesignData.DesignContentService>();

        }
        else
        {
            SimpleIoc.Default.Register<IContentService, LocalContentService>();
            SimpleIoc.Default.Register<IFeedAPI, FeedlyFeedAPI>();
        }

        SimpleIoc.Default.Register<ContentControlViewModel>();


    }

    public ContentControlViewModel ContentControlVm
    {
        get
        {
            return ServiceLocator.Current.GetInstance<ContentControlViewModel>();
        }
    }

    public static ViewModelLocator Instance
    {
        get
        {
            return Application.Current.Resources["Locator"] as ViewModelLocator;
        }
    }
}

以下のように IoC コンテナーを使用していない場合、すべてがうまく機能します (エラーはなく、完全に設計されたデータ)。

 public class ViewModelLocator
{
    private ContentControlViewModel _contentControlVm;
    public ContentControlViewModel ContentControlVm
    {
        get
        {
            if(_contentControlVm == null)
            {
                IContentService contentService = null;
                IFeedAPI feedApi = null;

                if (ViewModelBase.IsInDesignModeStatic)
                {
                    contentService = new DesignData.DesignContentService();
                    feedApi = new DesignData.DesignFeedAPI();
                }
                else
                {
                    contentService = new LocalContentService();
                    feedApi = new FeedlyFeedAPI();
                }

                _contentControlVm = new ContentControlViewModel(contentService, feedApi);
            }

            return _contentControlVm;
        }
    }

    public ViewModelLocator()
    {

    }

    public static ViewModelLocator Instance
    {
        get
        {
            return Application.Current.Resources["Locator"] as ViewModelLocator;
        }
    }
}
}

何か案は??

4

0 に答える 0