microsoft / TemplateStudio

Template Studio accelerates the creation of new WinUI 3, WPF, and UWP apps using a wizard-based experience.
Other
2.67k stars 457 forks source link

Design Mode doesn't work with default MVVMLight implementation #460

Open JeremyT17 opened 7 years ago

JeremyT17 commented 7 years ago

I created a basic app with MVVMLight and added one view and viewmodel. After adding design mode data it doesn't show up in Visual Studio design mode or Blend.

View Model Locator:

    {
        ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

        if(ViewModelBase.IsInDesignModeStatic)
        {
            SimpleIoc.Default.Register<IFooProvider, DesignFooProvider>();
        }
        else
        {
            SimpleIoc.Default.Register<IFooProvider, FooProvider>();
        }

        SimpleIoc.Default.Register(() => _navigationService);
        SimpleIoc.Default.Register<ShellViewModel>();
        Register<MainViewModel, MainPage>();
        Register<FooViewModel, FooView>();

        _navigationService.SetMainViewModel(MainViewModel);
    }

    public MainViewModel MainViewModel => ServiceLocator.Current.GetInstance<MainViewModel>();

    public ShellViewModel ShellViewModel => ServiceLocator.Current.GetInstance<ShellViewModel>();

    public FooViewModel FooViewModel => ServiceLocator.Current.GetInstance<FooViewModel>();

    public void Register<VM, V>() where VM : class
    {
        SimpleIoc.Default.Register<VM>();
        _navigationService.Configure(typeof(VM).FullName, typeof(V));
    }
}

FooViewModel has an ObservableCollection that is bound to in FooView.xaml Now when I run the actual code everything runs fine and my FooViewModel correctly gets populated with data from FooProvider.

Looking at FooView though in Visual Studio or Blend, no data is displayed in the ListBox of FooView.xaml.

(Note: The only code I added to the above class was related to FooView related items, the others were prepopulated).

crutkas commented 7 years ago

can you create a repro that we can throw a debugger against? That would help us solve the "Does this use nav pane? what pages? what features"

Assuming production

JeremyT17 commented 7 years ago

I debugged into it and the issue was this line:

SimpleIoc.Default.Register(() => _navigationService);

When running in design mode it said NavigationService was already registered. I threw it in a design mode check to fix the issue.

crutkas commented 7 years ago

ok, so this is an issue on your side? can we close this out? Do you feel this is an issue with our generated code?

JeremyT17 commented 7 years ago

I don't believe I created that line of code myself. It was most likely autogenerated so I would say it is still an issue that should be looked at.

crutkas commented 7 years ago

Can you give us the exact recipe you used along with your repro so we can look at a known failing project? Thanks! Really helps with debugging.

crutkas commented 7 years ago

@jtsmith3 any chance you provide how you generated?

mrlacey commented 6 years ago

Need to determine if still an issue and fix. Otherwise close.

Joebeazelman commented 6 years ago

Still an issue when working with a fresh Master Detail Page

crutkas commented 6 years ago

@Joebeazelman can you confirm your exact WTS version?

Joebeazelman commented 6 years ago

I am using the latest version.

On Wed, Jan 3, 2018 at 8:54 PM Clint Rutkas notifications@github.com wrote:

@Joebeazelman https://github.com/joebeazelman can you confirm your exact WTS version?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Microsoft/WindowsTemplateStudio/issues/460#issuecomment-355178894, or mute the thread https://github.com/notifications/unsubscribe-auth/ABxvjiVe5FIrIdHw0EIaXNmGBXDWbTQyks5tHC9jgaJpZM4N7RVi .

ralarcon commented 6 years ago

@Joebeazelman can you give us the repro steps (project configuration you have, pages and features added, etc...) we need to understand what is the root cause.

crutkas commented 6 years ago

@Joebeazelman what is your exact version of VS you're running? 15.5.2?