Infragistics(R) NetAdvantage(R) for WPF
Creating xamDataPresenter in Procedural Code


Glossary Item Box

This topic shows you how to create and add a xamDataPresenter™ control to your Window using procedural code.

To create xamDataPresenter in procedural code:

  1. Create a Microsoft® Windows® Presentation Foundation Window project.
  2. In the Solution Explorer, add the following references:
    • Infragistics3.Wpf.v7.2.dll
    • Infragistics3.Wpf.Editors.v7.2.dll
    • Infragistics3.Wpf.DataPresenter.v7.2.dll
  3. Name the default Grid layout panel in the Window so that you can reference it in the code-behind.

    In XAML:

    <Grid Name="layoutRoot">
    </Grid>
  4. Attach an event handler to the Window's Loaded event.

    In XAML:

    <Window ... Loaded="Window_Loaded"  ... >
    
  5. Open the code-behind and place using/Imports directives in your code-behind so you don't have to type out a member's fully qualified name.

    In Visual Basic:

    Imports Infragistics.Windows.DataPresenter

    In C#:

    using Infragistics.Windows.DataPresenter;
  6. Create a private Window level variable for the xamDataPresenter control.

    In Visual Basic:

    Private xamDataPresenter1 as XamDataPresenter
    

    In C#:

    private XamDataPresenter xamDataPresenter1;
    
  7. In the Window_Loaded event handler, initialize your private instance of xamDataPresenter and set its BindToSampleData property to True.

    In Visual Basic:

    xamDataPresenter1 = New XamDataPresenter()
    'You can data bind your instance of xamDataPresenter instead of using the built in sample data
    xamDataPresenter1.BindToSampleData = True

    In C#:

    xamDataPresenter1 = new XamDataPresenter();
    //You can data bind your instance of xamDataPresenter instead of using the built in sample data
    xamDataPresenter1.BindToSampleData = true;
  8. Add your instance of xamDataPresenter to the Grid layout panel's Children collection.

    In Visual Basic:

    Me.layoutRoot.Children.Add(xamDataPresenter1)

    In C#:

    this.layoutRoot.Children.Add(xamDataPresenter1);
  9. Run the project to see the xamDataPresenter control populated with sample data