【发布时间】:2014-09-09 20:34:49
【问题描述】:
我正在尝试向我的 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
}
【问题讨论】:
标签: c# wpf xaml devexpress