【问题标题】:DevExpress WPF Unbound Column with Expression Editor带有表达式编辑器的 DevExpress WPF 未绑定列
【发布时间】: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


    【解决方案1】:

    好的,我自己找到了答案。问题是如果您将“未绑定列”的概念添加到您的项目源(未绑定意味着数据未绑定到任何东西),它的概念就会失去意义。所以这里的解决方案是从 CustomRow 类中删除“Column3”属性,使 XAML 上定义的“Column3”成为真正的未绑定列。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 2013-01-01
      • 1970-01-01
      • 2015-11-11
      相关资源
      最近更新 更多