Forums
Forums are Read-Only. Use the new Support Center. To start a general discussion, use the General category when submitting your question.

Using DataTemplates that include Binding markup.

Last post 8/27/2009 9:53 AM by Ryan Tupper. 6 replies.
Sort Posts: Previous Next
  • Robert Claypool

    Using DataTemplates that include Binding markup.

    11/4/2008 12:46 AM
    • Not Ranked
    • Joined on 10/23/2008
    • Posts 5

    I want to use DataTemplates that include binding markup, but I am having problems doing this in AgDataGrid. 

    I put together this sample that illustrates the problem.  In the sample, I have both types of DataGrid control (Silverlight Standard and AgDataGrid).  Each bind to a list of employees and each are supposed to display the employee Name within a TextBox (within each row).  The standard Silverlight grid works.  AgDataGrid does not.  Do you see what mistake I have made?

    Thanks, RC

    ********************* Page.xaml: ******************
    <UserControl xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  x:Class="SilverlightApplication1.Page"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:my="clr-namespace:DevExpress.Windows.Controls;assembly=DevExpress.AgDataGrid.v8.2"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Width="400" Height="300">
        <Grid x:Name="LayoutRoot" Background="White">
            <Grid.RowDefinitions>
                <RowDefinition Height="0.5*"/>
                <RowDefinition Height="0.5*"/>
            </Grid.RowDefinitions>
            <my:AgDataGrid x:Name="agDataGrid" Grid.RowSpan="1" />
            <data:DataGrid x:Name="standardDataGrid" Grid.RowSpan="1" Grid.Row="1" />
        </Grid>
    </UserControl>

    ******************** Page.xaml.cs: *************************
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using DevExpress.Windows.Controls;
    using System.Text;
    using System.Windows.Markup;

    namespace SilverlightApplication1
    {
        public partial class Page : UserControl
        {
            public Page()
            {
                InitializeComponent();

                // get data
                var employees = this.GetEmployees();

                // bind it to both grids
                this.standardDataGrid.ItemsSource = employees;
                this.standardDataGrid.AutoGenerateColumns = false;
                this.agDataGrid.DataSource = employees;
                this.agDataGrid.AutoGenerateColumns = false;

                // create a template column for each grid
                var standardColumn = new DataGridTemplateColumn();
                var agColumn = new AgDataGridColumn();

                // Create a DataTemplate
                var sb = new StringBuilder();
                sb.Append("<DataTemplate ");
                sb.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' >");
                sb.Append("<TextBox Text='{Binding Name}' />");
                sb.Append("</DataTemplate>");
                var template = (DataTemplate)XamlReader.Load(sb.ToString());

                // Add it to the standard and ag columns we just created.
                standardColumn.CellTemplate = template;
                agColumn.CellDisplayTemplate = template;

                // Add the columns to thier respective grids.
                this.standardDataGrid.Columns.Add(standardColumn);
                this.agDataGrid.Columns.Add(agColumn);
            }

            private List<Employee> GetEmployees()
            {
                var employees = new List<Employee>();
                employees.Add(new Employee() { ID = 2, Name = "John Doe", DOB = DateTime.Now });
                employees.Add(new Employee() { ID = 3, Name = "Jane Doe", DOB = DateTime.Now });
                return employees;
            }
        }

        public class Employee
        {
            public int ID { get; set; }
            public string Name { get; set; }
            public DateTime DOB { get; set; }
        }
    }

  • Robert Claypool

    Re: Using DataTemplates that include Binding markup.

    11/4/2008 12:52 AM
    • Not Ranked
    • Joined on 10/23/2008
    • Posts 5

    Attached is the sample project.  You should be able to unzip this and run it with little effort. 

    Thanks again! RC

  • Robert Claypool

    Re: Using DataTemplates that include Binding markup.

    11/4/2008 6:36 PM
    • Not Ranked
    • Joined on 10/23/2008
    • Posts 5

    I figured this out.

    "{Binding Name}" works (as stated above) with the standard silverlight DataGrid.
    "{Binding RowValue.Name}" works with the AgDataGrid

    It's a small change, but one that took several hours to figure out!

    Robert Claypool, Nashville, TN

  • Kurt Mang

    Re: Using DataTemplates that include Binding markup.

    8/19/2009 6:41 PM
    • Not Ranked
    • Joined on 8/19/2009
    • Posts 10

    Thanks for posting - that was driving me nutz!

     

    Kurt Mang - Vancouver BC

  • Ryan Tupper

    Re: Using DataTemplates that include Binding markup.

    8/26/2009 4:15 PM
    • Not Ranked
    • Joined on 7/8/2008
    • Posts 4

    Hmm..


    {Binding RowValue.Name} worked in AgDataGrid before 9.2.4, now you get all kinds of errors like:

    BindingExpression path error: 'RowValue' property not found on 'DevExpress.AgEditors.TextEdit

    in the output log when debugging...


    What is the new way to get at the data in a row now in 9.2.4?

  • Chris Walsh [DX-Squad]

    Re: Using DataTemplates that include Binding markup.

    8/26/2009 7:27 PM
    • Top 50 Contributor
    • Joined on 3/13/2009
    • Melbourne, Australia
    • Posts 1,096

    Ryan,

    This is a bug, and as now been fixed... See Here

    Chris Walsh [DX-Squad]
    Tweet Me
    My Blog
  • Ryan Tupper

    Re: Using DataTemplates that include Binding markup.

    8/27/2009 9:53 AM
    • Not Ranked
    • Joined on 7/8/2008
    • Posts 4

    Ok, so what is the correct syntax in xaml now for accessing row data in a column? 

    RowValue doesn't work.

    Edit.DataContext.RowValue doesn't work

    Yesterday on the regular 9.2.4 I tried DataContext.RowValue and that at first appears to work, the RowValue doesn't appear to be right, as if its getting the first rows value always even if your on row 10 or 20 or whatever.

    Edit: I tried this on the 9.2.4.9239 and it exhibits the same behavior if you use DataContext.RowValue, the value of RowValue is definitely for other rows sometimes...

    I reported this as a bug here: http://www.devexpress.com/Support/Center/p/B139416.aspx

    The bug includes an example which clearly shows the problem.

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.