Data Access has been discontinued. Please refer to this page for more information.

Setting up the Secondary View

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

In this step you will set up the secondary view of the project. It will be called through the main view - MainWindow and will allow you to edit existing cars or add new ones to the database. To set it up you will need to define an interface exposing its functionality, create a class defining its base behavior, add and configure a new WPF Window.

Defining the secondary view`s interface

The secondary view will act as a dialog window and thus needs to expose functionality which would allow it to do so. In the ViewInterfaces folder add a new Interface named IDialogView deriving from IView.

public interface IDialogView : IView
{
    bool? ShowDialog();
    bool? DialogResult { get; set; }
    System.Windows.Window Owner { get; set; }
}
Public Interface IDialogView
    Inherits IView
    Function ShowDialog() As Boolean?
    Property DialogResult As Boolean?
    Property Owner As Window
End Interface

Creating the BaseDialogWindow class

Since the secondary view should act as a dialog window, it needs to be able to be initialized as such. To do that you should create a new class in the Views folder named BaseDialogWindow which derives from Window. In its default constructor, initialize the required window properties

public class BaseDialogWindow : Window
{
    public BaseDialogWindow()
    {
        this.Owner = App.Current.MainWindow;
        this.ShowInTaskbar = false;
        this.ResizeMode = System.Windows.ResizeMode.NoResize;
        this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
    }
}
Public Class BaseDialogWindow
    Inherits Window
    Public Sub New()
        Me.Owner = Application.Current.MainWindow
        Me.ShowInTaskbar = False
        Me.ResizeMode = Windows.ResizeMode.NoResize
        Me.WindowStartupLocation = Windows.WindowStartupLocation.CenterOwner
        Me.ShowInTaskbar = False
    End Sub
End Class

Setting up the window

  1. In the Views folder add a new WPF Window with name AddEditWindow.
  2. Open the XAML view of AddEditWindow and change the name of the opening tag from Window to local:BaseDialogWindow. This way the window will be actually be an instance of the class defined earlier - BaseDialogWindow.
  3. In the code behind of AddEditWindow inherit the BaseDialogWindow class and implement the IDialogView interface.

    public partial class AddEditWindow : BaseDialogWindow, IDialogView
    {
        public AddEditWindow()
        {
            InitializeComponent();
        }
    } 
    
    Partial Public Class AddEditWindow
        Inherits BaseDialogWindow
        Implements IDialogView
        Public Sub New()
            InitializeComponent()
        End Sub
        Public Overloads Property DialogResult As Boolean? Implements IDialogView.DialogResult
            Get
                Return MyBase.DialogResult
            End Get
            Set(value As Boolean?)
                MyBase.DialogResult = value
            End Set
        End Property
        Public Overloads Property Owner As Window Implements IDialogView.Owner
            Get
                Return MyBase.Owner
            End Get
            Set(value As Window)
                MyBase.Owner = value
            End Set
        End Property
        Public Overloads Property DataContext As Object Implements IView.DataContext
            Get
                Return MyBase.DataContext
            End Get
            Set(value As Object)
                MyBase.DataContext = value
            End Set
        End Property
        Public Overloads Function ShowDialog() As Boolean? Implements IDialogView.ShowDialog
            Return MyBase.ShowDialog()
        End Function
        Public Overloads Sub Close() Implements IView.Close
            MyBase.Close()
        End Sub
    End Class
    

Next step: Dfining the User Interface of MainWindow