Quantcast
Channel: MVVM Light Toolkit
Viewing all articles
Browse latest Browse all 1826

Edited Unassigned: MVVMLight WPF template for App.xaml causing Blend 2013 to crash. [7680]

$
0
0
I've come across a problem with the default template used for the App.xaml when adding MVVM Light to an existing/new project via NuGet.

The problem occurs in Blend when you try and create a new ResourceDictionary, either via the [Add New Item] method, or using the [New] button in a Create Color Resource dialog.

STEPS TO RECREATE:

1. Create new WPF project.
2. Install MVVMLight package via NuGet.
3. Open project in Blend 2013.
4. Select menu FILE -> ADD ITEM, and select ResourceDictionary.

Blend throws and exception at this point, and exits.

The error seems to occur when Blend attempts to add the new file to a MergedDictionary entry in App.xaml.

The error appears to be caused by the <vm:ViewModelLocator ...> entry, as commenting this out resolves the problem.

__WORKAROUND:__

When MVVM Light is installed by the PackageManager, it writes this into the app.xaml:

```
<Application x:Class="ProjectName.App"
StartupUri="MainWindow.xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006"
d1p1:Ignorable="d">
<Application.Resources>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:ProjectName.ViewModel" />
</Application.Resources>
</Application>
```

It's this default app.xaml that is causing Blend to crash.

However, by nesting the <vm:ViewModelLocator ...> resource in a ResourceDictionary:

```
<Application x:Class="ProjectName.App"
StartupUri="MainWindow.xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:d1p1="http://schemas.openxmlformats.org/markup-compatibility/2006"
d1p1:Ignorable="d">
<Application.Resources>
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" xmlns:vm="clr-namespace:ProjectName.ViewModel" />
</ResourceDictionary>
</Application.Resources>
</Application>
```

... Blend no longer throws an exception, and the new resourcedictionary is added to the App.xaml.


Viewing all articles
Browse latest Browse all 1826

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>