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

Initializing MainViewModel

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.

At this point you have a view model able to retrieve cars from the database and a view bound to it, but the model is not called from anywhere nor is the view displayed. You will need to initialize the model and display the associated view in the entry point of the application.

  1. In MainViewModel add a method Show(). This method should call the Show() method of the associated view.

    public void Show()
    Public Sub Show()
    End Sub
  2. In the XAML view of app.xaml or application.xaml remove the StartupUri property from the opening Application tag.

  3. In the code behind of app.xaml or application.xaml define a field mainViewModel for the main view model.

    private CarsViewModel mainViewModel;
    Private _mainViewModel As CarsViewModel
  4. The OnStartup event handler is the entry point of the application, here you need to initialize the main view model and display its view.

    protected override void OnStartup(StartupEventArgs e)
        this.mainViewModel = new CarsViewModel();
    Protected Overrides Sub OnStartup(e As StartupEventArgs)
        Me._mainViewModel = New CarsViewModel()
    End Sub
  5. In the Application_Exit event handler you need to dispose of mainViewModel.

    private void Application_Exit(object sender, ExitEventArgs e)
        if (this.mainViewModel != null)
    Private Sub Application_Exit(sender As Object, e As ExitEventArgs)
        If IsNothing(Me._mainViewModel) = False Then
        End If
    End Sub


The application now is able to start up and display the cars available in the database.

Next step: Filtering and Refreshing the Displayed Data