DEV Community

Cover image for WPF DataGrid in 2 minutes

WPF DataGrid in 2 minutes

John Peters
Lit-Html or Svelte?
・2 min read
  • Create a folder named Models, then create a class definition like this:
class IWebElementList : ObservableCollection<IWebElement> {}
Enter fullscreen mode Exit fullscreen mode

The ObservableCollection is a part of this library:

using System.Collections.Generic;
Enter fullscreen mode Exit fullscreen mode

We are modeling a collection Selenium IWebElements. That class is defined here:

using OpenQA.Selenium;
Enter fullscreen mode Exit fullscreen mode
  • Create a new UserControl and name it ElementGrid.
  • Click on View/Other Window/Data Sources

Alt Text

  • Click on Add New
    Alt Text

  • Click on Object
    Alt Text

  • Select the Model
    Alt Text

  • Once imported...
    You should be able to select the presentation layout, note it defaults to a datagrid
    Alt Text

  • Drag the DataSource to the UserControl.
    Alt Text

  • Instant Data Grid
    Alt Text

  • Auto Generated XAML
    Alt Text

  • Auto Generated Code
    Alt Text

Uncomment the code parts, and notice there are two areas requiring our attention.

"your data" will be an instance of an ObservableCollection . This will come directly from Selenium.

"Resource Key..." will be found in the User Control pages, Resources area as shown here.

Alt Text

Congratulations, you've just created a GUI interface to Selenium in literally 2 minutes.

This same technique works for any model. In a future article we'll discuss the benefits of the CollectionViewSource.

JWP2021 Instant DataGrid

Discussion (0)