Show Contents of ContentControl from Base Class

Topics: Extensibility, UI Architecture
Jan 18, 2013 at 8:21 PM
Edited Jan 18, 2013 at 8:25 PM

Edit: Please disregard this post.  I acidently had the wrong view named GenericDialogView.

 

 

I have created a GenericDialogView and ViewModel:

 

<Window   x:Class="InspectUs.WPF.Views.BuildingDialogView"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
          mc:Ignorable="d" 
          Height="177" Width="320" Title="Edit Building" ShowInTaskbar="False" ResizeMode="NoResize">
    <Grid Margin="4">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <ContentControl x:Name="DialogContentsViewModel"/>

        <StackPanel x:Name="Buttons" Grid.ColumnSpan="6" Grid.Row="1" Orientation="Horizontal" Margin="8" HorizontalAlignment="Right">
            <Button x:Name="Ok" Content="OK" Margin="0,0,4,0" Width="50" IsDefault="True"/>
            <Button x:Name="Cancel" Content="Cancel" Margin="4,0,0,0" Width="50" IsCancel="True"/>
        </StackPanel>
    </Grid>

</Window>
    public abstract class GenericDialogViewModel<T> : Screen
    {
        private T dialogContentsViewModel;

        public T DialogContentsViewModel {
            get { return dialogContentsViewModel; }
            private set
            {
                dialogContentsViewModel = value;
                NotifyOfPropertyChange(() => DialogContentsViewModel);
            }
        } 

        public void SetContentsViewModel(T viewModel)
        {
            DialogContentsViewModel = viewModel;
        }

        public abstract void Ok();

        public virtual void Cancel()
        {
            TryClose();
        }

    }

 

I modified the ViewLocator to show the view associated with the base class of my ViewModel and that is working.  My problem is that when I call SetContentsViewModel on the child ViewModel I am not seeing the contents shown in the view during program execution.

 

Does anyone have any thoughts?