Prism icon indicating copy to clipboard operation
Prism copied to clipboard

View Template Design Time ViewModel

Open pdinnissen opened this issue 9 years ago • 2 comments

The Prism Template Pack is fantastic, but I'm curious if others would agree that getting a design time viewmodel instance would be extremely handy to have in the View Template.

Only a few lines would need to be added:

<UserControl x:Class="AssemblyName.Views.View"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:prism="http://prismlibrary.com/"             
             prism:ViewModelLocator.AutoWireViewModel="True"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vm="clr-namespace:AssemblyName.ViewModels">
    <d:UserControl.DataContext>
        <vm:ViewModel />
    </d:UserControl.DataContext>
    <Grid>
        

    </Grid>
</UserControl>

and in the a parameterless constructor for the ViewModel:

public ViewModel()
        {
            if (DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                // Initialize design time data
            }
        }

I'm sure there's other possible solutions, but this is what I've been using in my projects. I also realize that I can create my own template, but felt that it might be a good idea to promote this design time code in the template pack for others to get the same benefits.

pdinnissen avatar Nov 23 '17 12:11 pdinnissen

Thanks for the suggestion. Could you please post this in the proper repo? Thanks>

https://github.com/PrismLibrary/Prism-Extensibility

brianlagunas avatar Nov 23 '17 16:11 brianlagunas

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Jan 29 '20 10:01 lock[bot]