2010-09-01 29 views
0

請原諒這個新手問題,但我正在加緊Silverlight和MVVM Light。我創建了一個名爲MyView.xaml的視圖和一個對應的MyViewModel.cs。如何防止在DataForm中呈現基類屬性?

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"> 

<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; } 
    } 
} 

當我運行該項目,我的形式呈現IsInDesignMode財產。我顯然不想要這個。我怎樣才能防止在數據表單中呈現基類屬性?

謝謝。

安德魯

回答

0

如果你只是想阻止人們展示了申請,您可以訂閱AutoGeneratingField事件,並在事件參數傳遞給真正取消標誌。如果要實現自己的佈局,可以將AutoGeneratingFields標誌設置爲false並提供自己的模板。

+0

謝謝,凱爾。訂閱AutoGeneratingField事件運行良好。 – Andrew 2010-09-09 20:04:39