如何在XAML中绑定dataform

时间:2011-05-12 03:24:23

标签: c# silverlight-4.0 wcf-ria-services dataform

....
xmlns:viewmodel="clr-namespace:MyRecipe.ViewModels">

<navigation:Page.Resources>
    <viewmodel:RecipeViewModel x:Key="RecipeViewModel" />
</navigation:Page.Resources>

<toolkit:DataForm x:Name="form" 
        HorizontalAlignment="Left" VerticalAlignment="Top"
        ItemsSource="{Binding Recipes}" Width="500" Height="600" />

在viewmodel中:

public EntitySet<Recipe> Recipes
{
    get { return _recipes; }
    set
    {
        if (_recipes != value)
        {
            _recipes = value;
            OnPropertyChanged("Recipes");
        }
    }
}

我想将数据表单绑定到Recipes实体集。数据形式未显示任何字段或任何指示它已绑定。怎么了?

1 个答案:

答案 0 :(得分:0)

修正:

<toolkit:DataForm x:Name="form" 
HorizontalAlignment="Left" VerticalAlignment="Top"
DataContext="{StaticResource RecipeViewModel}" 
ItemsSource="{Binding Recipes}" Width="500" Height="600" />

必须添加DataContext行。