我试图在我的GridControl中添加一个未绑定的列,同时在其上启用表达式编辑器,这样当我打开它并编写一个有效的表达式时,列值应该相应地改变,但是它“#”;不工作我有一个包含3列的GridControl:Column1,Column2和Column3。 Column3是未绑定的。表达式编辑器正确打开,让我编写表达式,但是当我单击“确定”时,值永远不会改变,与我写的内容无关。
我使用的是DevExpress 13.1,无法升级。这是我的代码:
XAML:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
x:Class="ExpressionEditor.MainWindow"
Title="Expression Editor" Height="350" Width="525">
<dxg:GridControl x:Name="myGridControl">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Column1" />
<dxg:GridColumn FieldName="Column2" />
<dxg:GridColumn FieldName="Column3"
UnboundType="Decimal"
ReadOnly="True" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView x:Name="myTableView"
NavigationStyle="Cell" />
</dxg:GridControl.View>
</dxg:GridControl>
</Window>
代码背后:
using System.Collections.ObjectModel;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
#region Properties
/// <summary>
/// Gets or sets the data table2.
/// </summary>
/// <value>
/// The data table2.
/// </value>
public ObservableCollection<CustomRow> DataTable { get; set; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="MainWindow"/> class.
/// </summary>
public MainWindow()
{
this.InitializeComponent();
this.DataTable = new ObservableCollection<CustomRow>();
this.myGridControl.ItemsSource = this.DataTable;
this.Init();
}
#endregion
#region Methods
private void Init()
{
// Add Data
this.DataTable.Add(new CustomRow { Column1 = 100, Column2 = 200 });
this.DataTable.Add(new CustomRow { Column1 = 300, Column2 = 400 });
// Add Unbound Column
var column = this.myGridControl.Columns["Column3"];
column.AllowUnboundExpressionEditor = true;
}
#endregion
}
CustomRow类:
/// <summary>
/// Custom Row
/// </summary>
public class CustomRow
{
#region Properties
/// <summary>
/// Gets or sets the column1.
/// </summary>
/// <value>
/// The column1.
/// </value>
public double Column1 { get; set; }
/// <summary>
/// Gets or sets the column2.
/// </summary>
/// <value>
/// The column2.
/// </value>
public double Column2 { get; set; }
/// <summary>
/// Gets or sets the column3.
/// </summary>
/// <value>
/// The column3.
/// </value>
public double Column3 { get; set; }
#endregion
}
答案 0 :(得分:0)
好的,我自己找到了答案。问题是“UNBOUND Column”的概念如果将其添加到项目源中则失去意义(Unbound意味着数据未绑定到任何内容)。所以这里的解决方案是从CustomRow类中删除“Column3”属性,使在XAML上定义的“Column3”成为一个真正的未绑定列。