在Xceed DataGrid MultiBinding中进行分组和排序 [英] Grouping and Sorting in Xceed DataGrid MultiBinding

查看:59
本文介绍了在Xceed DataGrid MultiBinding中进行分组和排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在研究一个Xceed DataGrid,其中一个单元格将包含两个值,这意味着一个属于该单元格的属性将具有自定义类类型的属性,该属性具有[ValueText属性]和BackGround]其中ValueText应该被限制为显示文本和Background属性应该绑定到Cell Background属性,它为我工作文件。我使用下面的DataTemplate来实现这一点。



Hi,
I was working on a Xceed DataGrid on which a cell will hold two values which mean a property bounded to the cell will have property of a custom class type which has property of [ ValueText and BackGround] of which the ValueText should be bounded to display text and Background Property should be bounded to Cell Background property which works file for me. And am using the below DataTemplate to achieve this.

<DataTemplate x:Key="ShipCountryDataTemplate" DataType="{x:Type localData:DQMCell}">
            <Grid VerticalAlignment="Center" HorizontalAlignment="Center" Margin="-2" removed="{Binding Path=Background, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataCell}}, Path=ActualHeight}"

                        Width="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataCell}}, Path=ActualWidth}">
                <TextBlock Text="{Binding Path=ValueText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="4" />
            </Grid>
        </DataTemplate>





和我的DataGrid配置在下面





and my DataGrid Configuration is below

<egldg:EagleDataGrid x:Name="DataQualityMonitoringViewDataGrid"

                             ItemsSource="{Binding}" 

                             ShowGroupPanel="True" 

                             ShowRowNumber="True"

                             ReadOnly="True"

                             GridID="DQMVIEWDATAGRID"

                             AutoCreateColumns="False" 

                             ShowRowDetailsOnDoubleClick="False"

                             CellEditorDisplayConditions="None"

                             AllowGrouping="True">
            <egldg:EagleDataGrid.View>
                <xcdg:TableView  AllowColumnChooser="True" 

                                ShowFixedColumnSplitter="True"

                                ColumnChooserSortOrder="None"

                                HorizontalGridLineThickness="0.1">
                    <xcdg:TableView.Theme>
                        <egltheme:DataGridAeroTheme />
                    </xcdg:TableView.Theme>
                </xcdg:TableView>
            </egldg:EagleDataGrid.View>
            <egldg:EagleDataGrid.Columns>
                <xcdg:Column FieldName="Status_15010" Title="{x:Static  Localization:EagleResources.DG_COL_STATUS}" IsMainColumn="True" CellContentTemplate="{StaticResource DQMCELLDataTemplate}">
                    <xcdg:Column.GroupDescription>
                        <localData:DQMCellDataGridGroupDescription PropertyName="Status_15010" SortComparer="{StaticResource dQMCellComparer}"/>
                    </xcdg:Column.GroupDescription>
                </xcdg:Column>
                <xcdg:Column FieldName="RunDate_15011"  Title="{x:Static  Localization:EagleResources.DG_COL_RUN_DATE}" CellContentTemplate="{StaticResource DQMCELLDataTemplate}">
                    <xcdg:Column.GroupDescription>
                        <localData:DQMCellDataGridGroupDescription PropertyName="RunDate_15011" SortComparer="{StaticResource dQMCellComparer}"/>
                    </xcdg:Column.GroupDescription>
                </xcdg:Column>
                <xcdg:Column FieldName="EffectiveDate_15012" Title="{x:Static  Localization:EagleResources.DG_COL_EFFECTIVE_DATE}" CellContentTemplate="{StaticResource DQMCELLDataTemplate}">
                    <xcdg:Column.GroupDescription>
                        <localData:DQMCellDataGridGroupDescription PropertyName="EffectiveDate_15012" SortComparer="{StaticResource dQMCellComparer}"/>
                    </xcdg:Column.GroupDescription>
                </xcdg:Column>
                <xcdg:Column FieldName="ListComposite_15013" Title="{x:Static  Localization:EagleResources.DG_COL_LIST_COMPOSITE}" CellContentTemplate="{StaticResource DQMCELLDataTemplate}">
            </egldg:EagleDataGrid.Columns>
        </egldg:EagleDataGrid>







我的问题是当我想将一个列组合在一起时,它的类型为DQMCELL到我的DataTemplate DataType。但我实际上需要与该列值组合。这实际上并没有发生。帮我解决这个问题。任何分组模板或Xceed DataGrid上的任何想法,请与我分享。





如果有人可以,请让我知道'理解我的问题



这是我的CollectionType






My Question is when I suppose to Group a column it group with the type DQMCELL which i have bounded to my DataTemplate DataType. but i actually need to group with that column value. which was not actually happening. help me on this to fix this issue. Any Grouping template or any idea on Xceed DataGrid you have please share it with me.


Please Let me know if any one can't understand my Question

This was my CollectionType

public class DataQualityMonitoringData : IEquatable<DQMCell>, INotifyPropertyChanged
    {
        private DQMCell DG_COL_RUN_DATE = new DQMCell();

        public DQMCell RunDate_15011
        {
            get { return DG_COL_RUN_DATE; }
            set
            {
                DG_COL_RUN_DATE = value;
                OnPropertyChanged("RunDate_15011");
            }
        }

        private DQMCell DG_COL_EFFECTIVE_DATE = new DQMCell();

        public DQMCell EffectiveDate_15012
        {
            get { return DG_COL_EFFECTIVE_DATE; }
            set
            {
                DG_COL_EFFECTIVE_DATE = value;
                OnPropertyChanged("EffectiveDate_15012");
            }
        }

        private DQMCell DG_COL_LIST_COMPOSITE = new DQMCell();

        public DQMCell ListComposite_15013
        {
            get { return DG_COL_LIST_COMPOSITE; }
            set
            {
                DG_COL_LIST_COMPOSITE = value;
                OnPropertyChanged("ListComposite_15013");
            }
        }


        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// On property changed method
        /// </summary>
        /// <param name="propertyName">Property Name</param>
        void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

        #region IEquatable Member

        public override int GetHashCode()
        {
            int rundate_15011 = RunDate_15011.GetHashCode();
            int effectivedate_15012 = EffectiveDate_15012.GetHashCode();
            int listcomposite_15013 = ListComposite_15013.GetHashCode();
            return rundate_15011
                ^ effectivedate_15012
                ^ listcomposite_15013;
        }

        public bool Equals(DQMCell other)
        {
            if (Object.ReferenceEquals(other, null)) return false;
            if (Object.ReferenceEquals(this, other)) return false;

            return RunDate_15011.ValueText.Equals(other.ValueText)
                && EffectiveDate_15012.ValueText.Equals(other.ValueText)
                && ListComposite_15013.ValueText.Equals(other.ValueText);
        }

        #endregion
    }





and the DQMCELL class





and the DQMCELL class

public class DQMCell : INotifyPropertyChanged, IEquatable<DQMCell>
    {
        public DQMCell()
        {
            this.ValueText = string.Empty;
            this.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString(Constants.REDCOLOR));
        }
        private string _val = string.Empty;
        public string ValueText
        {
            get { return _val; }
            set
            {
                _val = value;
                OnPropertyChanged("ValueText");
            }
        }

        private SolidColorBrush bg_Brush;
        public SolidColorBrush Background
        {
            get { return bg_Brush; }
            set
            {
                bg_Brush = value;
                OnPropertyChanged("Background");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

        #region IEquatable Member
        public override int GetHashCode()
        {
            int valueText = ValueText.GetHashCode();
            int background = Background.GetHashCode();
            return valueText ^ background;
        }

        public bool Equals(DQMCell other)
        {
            if (Object.ReferenceEquals(other, null)) return false;
            if (Object.ReferenceEquals(this, other)) return false;

            return ValueText.Equals(other.ValueText)
                && Background.Equals(other.Background);
        }

        #endregion
    }





the Collection type of DataQualityMonitoringData is bounded to the DataGrid.



Binding Logic





the Collection type of DataQualityMonitoringData is bounded to the DataGrid.

Binding Logic

List<DataQualityMonitoringData> dataQualityMonitoringData = CommonUtils.dataQualityMonitoringDataCollection.GetMainDataTable(false);
                DataGridCollectionView d_view = new DataGridCollectionView(dataQualityMonitoringData);
                Binding bind = new Binding();
                d_view.AutoFilterMode = AutoFilterMode.And;
                bind.Source = d_view;
                DataQualityMonitoringViewDataGrid.SetBinding(DataGridControl.ItemsSourceProperty, bind);







I have Fixed the Grouping Issue i have implemented the below two. IComparer and DataGridGroupDescription




I have Fixed the Grouping Issue i have implemented the below two. IComparer and DataGridGroupDescription

public class DQMCellComparer : IComparer
    {
        public int Compare(object x, object y)
        {
            if (x == null || y == null) return 0;
            string dQMCell_x = x as string;
            string DQMCell_y = y as string;
            if (dQMCell_x.CompareTo(DQMCell_y) != 0)
            {
                return dQMCell_x.CompareTo(DQMCell_y);
            }
            return 0;
            throw new NotImplementedException();
        }
    }

    public class DQMCellDataGridGroupDescription : DataGridGroupDescription
    {
        public DQMCellDataGridGroupDescription()
            : base()
        {

        }

        public DQMCellDataGridGroupDescription(string propertyName)
            : base(propertyName)
        {

        }

        public override object GroupNameFromItem(object item, int level, System.Globalization.CultureInfo culture)
        {
            object value = base.GroupNameFromItem(item, level, culture);
            try
            {
                DQMCell content = value as DQMCell;
                if (content == null) return "";
                value = content.ValueText;
            }
            catch (InvalidCastException)
            {
            }
            return value;

        }
    }





But Still i have Sorting Issue :(



But Still i have Sorting Issue :(

推荐答案

这篇关于在Xceed DataGrid MultiBinding中进行分组和排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆