View not getting rendered using DataTemplate - Resolved

Topics: Prism v4 - WPF 4
Jun 26, 2011 at 3:59 PM
Edited Jun 26, 2011 at 4:00 PM

Hi,

Following the MVVM concept, I am trying to create a simple Prism application, wherein I resolve an OrderViewModel in my ShellViewModel and then add it to "MainRegion" of Shell View as shown below.

 

            IRegion mainRegion = regionManager.Regions["MainRegion"];
            OrderViewModel orderViewModel =
                ServiceLocator.Current.GetInstance<OrderViewModel>();
            mainRegion.Add(orderViewModel);
There is a DataTemplate defined in my Application resources which has DataType OrderViewModel as shown below.

 

 

    <Application.Resources>
        <DataTemplate DataType="{x:Type vm:OrderViewModel}">
            <vm:OrderView/>
        </DataTemplate>
    </Application.Resources>

 

My problem is that the OrderView as identified by DataTemplate is not picked up by Prism (or WPF). Instead the OrderViewModel's namespace qualified name is displayed in the window. Please help me solve this issue.

regards,

Nirvan.

Jun 27, 2011 at 2:48 AM

Resolved. Need to merge resource dictionary of the assembly holding the DataTemplate with the main application resources like this

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary 
                    Source="/OrderModule;component/DataTemplates.xaml">
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>

Although this approach is not ideal, it works. Will try to remove the dependency using a cleaner approach.

Nirvan.