Version

Accessing Cell Values in the Active Record

Before You Begin

You can access Cell values in xamDataPresenter’s™ active Record using Extensible Application Markup Language (XAML). This will allow you to bind the value of a Cell in the active Record to the Text property of a TextBox control. You can use this functionality to create a section in your Window for data entry or for data navigation and display purposes.

What You Will Accomplish

You will create a section in your Window for data entry tasks using XAML.

Follow these Steps

  1. Create RowDefinitions for the default Grid layout panel in your Window.

    In XAML:

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="3*" />
            <RowDefinition Height="2*" />
        </Grid.RowDefinitions>
        <!--TODO: Add controls here-->
    </Grid>
  1. Add a xamDataPresenter control to your Window.

    1. Name the xamDataPresenter control so you can reference it later.

    2. Set the BindToSampleData property to True. This topic will use the sample data in order to concentrate on the topic at hand.

    3. Set the attached Grid.Row property to 0.

    In XAML:

    ...
    <igDP:XamDataPresenter Name="xamDataPresenter1" BindToSampleData="True" Grid.Row="0">
    </igDP:XamDataPresenter>
    ...
  1. Disable editing of the xamDataPresenter control since you will use the TextBox controls to modify the Cell values.

    1. Declare tags for the FieldSettings property within the tags of xamDataPresenter.

    2. Add a FieldSettings object within the tags for the FieldSettings property.

    3. Set the AllowEdit property of the FieldSettings object to False.

    In XAML:

    ...
    <igDP:XamDataPresenter.FieldSettings>
        <igDP:FieldSettings AllowEdit="False" />
    </igDP:XamDataPresenter.FieldSettings>
    ...
  1. Add a StackPanel layout container to your Window.

    1. Set the attached Grid.Row property to 1.

    2. Use a binding expression to set the DataContext property of the StackPanel container to the ActiveRecord property of the xamDataPresenter1 control. By setting the DataContext of the parent container, you can use simpler binding expressions to set properties on its children.

    In XAML:

    ...
    <StackPanel
        Grid.Row="1"
        DataContext="{Binding ElementName=xamDataPresenter1, Path=ActiveRecord}">
        <!--TODO: Add data entry controls here-->
    </StackPanel>
    ...
  1. Add a TextBlock control to the StackPanel layout container and set the TextBlock’s Text property.

    In XAML:

    ...
    <TextBlock Text="Name:" />
    ...
  1. Add a TextBox control to the StackPanel layout container and use a binding expression to bind the Text property to the Value property of a Cell in the Cells collection.

    Since you set the parent layout container’s DataContext to the xamDataPresenter1 control’s ActiveRecord property, you can simply use a property path to get the values from a Cell.

    In XAML:

    ...
    <TextBox Text="{Binding Path=Cells[name].Value}" />
    ...
  1. Repeat steps six and seven for each Field you want to display and/or edit.

    In XAML:

    ...
    <TextBlock Text="Department:" />
    <TextBox Text="{Binding Path=Cells[department].Value}" />
    <TextBlock Text="Salary:" />
    <TextBox Text="{Binding Path=Cells[salary].Value}" />
    <TextBlock Text="Email Address:" />
    <TextBox Text="{Binding Path=Cells[email].Value}" />
    ...
  1. Run the project and click a Record to activate it. The values in the Cells of the Record you just clicked on should be displayed in the TextBox controls. If you modify a value in a TextBox and the TextBox loses focus, the value in the corresponding Cell will also update.

    accesing cell values in xamdatapresenter's active record