views:

1029

answers:

2

I’m trying out the Silverlight 4 beta DataForm control. I don’t seem to be able to get the edit and paging options at the top of the control like I’ve seen in Silverlight 3 examples. Has something changed or am I doing something wrong? Here’s my code:

<UserControl x:Class="SilverlightApplication7.MainPage"
    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"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:dataFormToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit">

    <Grid x:Name="LayoutRoot" Background="White">
        <dataFormToolkit:DataForm HorizontalAlignment="Left" Margin="10" Name="myDataForm" VerticalAlignment="Top" />
    </Grid>
</UserControl>

public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            Movie movie = new Movie();  
            myDataForm.CurrentItem = movie; 
        }

        public enum Genres
        {
            Comedy,
            Fantasy,
            Drama,
            Thriller
        }

        public class Movie
        {
            public int MovieID { get; set; }
            public string Name { get; set; }
            public int Year { get; set; }
            public DateTime AddedOn { get; set; }
            public string Producer { get; set; }
            public Genres Genre { get; set; }
        }  
    }
+1  A: 

The behaviour of your code above is identical in VS2008+SL3.

The DataForm only provides the navigation bar if you provide it with a set of items assigned to the ItemsSource property. By assigning directly to the CurrentItem property you are in effect asking the DataForm "please edit this item", which is exactly what its doing.

AnthonyWJones
A: 

AnthonyWJones is correct on the paging question. You need to bind to the collection to get the Next/Previous options. I believe you need to implement IEditableObject for the View/Edit option to appear.

miketrash