views:

50

answers:

1

Hello all,

Please excuse this novice question, but I'm ramping up on Silverlight and MVVM Light. I created a view called MyView.xaml and a corresponding MyViewModel.cs.

MyView.xaml

<navigation:Page x:Class="Dashboard.Views.MyView" 
       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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
       xmlns:vm="clr-namespace:Dashboard.ViewModels"
       xmlns:controls="clr-namespace:Dashboard.Controls"
       mc:Ignorable="d"
       xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
       d:DesignWidth="640" d:DesignHeight="480"
       Title="MyView Page" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"&gt;

<navigation:Page.Resources>
    <vm:MyViewModel x:Key="MyViewModel" />
</navigation:Page.Resources>

<navigation:Page.DataContext>
    <Binding Source="{StaticResource MyViewModel}"/>
</navigation:Page.DataContext>

<Grid x:Name="LayoutRoot">
    <StackPanel Orientation="Vertical" Style="{StaticResource LoginControlsStackPanelStyle}" HorizontalAlignment="Center" VerticalAlignment="Center">
        <toolkit:DataForm Name="dataForm1" CurrentItem="{Binding}"/>
    </StackPanel>
</Grid>

MyViewModel.cs

namespace Dashboard.ViewModels
{
    public class MyViewModel : ViewModelBase
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
}

When I run the project, my form renders the IsInDesignMode property. I obviously do not want this. How can I prevent the base class property from rendering in the dataform?

Thanks.

Andrew

A: 

If you only want to prevent one filed from showing up, you can subscribe to the AutoGeneratingField event and set the Cancel flag on the events args to true. If you want to implement your own layout, you can set the AutoGeneratingFields flag to false and provide your own templates.

Kyle McClellan
Thank you, Kyle. Subscribing to the AutoGeneratingField event worked well.
Andrew