Exemple #1
0
        protected virtual void SetTitleBarContentBinding(DataGridContext dataGridContext)
        {
            if (dataGridContext != null)
            {
                Xceed.Wpf.DataGrid.Views.ViewBase view = dataGridContext.DataGridControl.GetView();

                if ((view is TableView) ||
                    (view is TableflowView))
                {
                    return;
                }

                Column headerColumn = dataGridContext.Columns.MainColumn as Column;

                if (headerColumn != null)
                {
                    // Disable warning for DisplayMemberBinding when internaly used
#pragma warning disable 618

                    BindingBase displayMemberBinding = headerColumn.DisplayMemberBinding;

#pragma warning restore 618

                    if (displayMemberBinding == null)
                    {
                        if (dataGridContext.ItemsSourceFieldDescriptors == null)
                        {
                            throw new InvalidOperationException("An attempt was made to create a DisplayMemberBinding before the DataGridContext has been initialized.");
                        }

                        string name = headerColumn.FieldName;
                        ItemsSourceHelper.FieldDescriptor fieldDescriptor;
                        dataGridContext.ItemsSourceFieldDescriptors.TryGetValue(name, out fieldDescriptor);

                        displayMemberBinding = ItemsSourceHelper.CreateDefaultBinding(
                            this.DataContext is DataRow, name, fieldDescriptor,
                            false, true, typeof(object));
                    }

                    if (displayMemberBinding == null)
                    {
                        Debug.Assert(false, "displayMemberBinding is null.");
                        this.ClearValue(DataRow.TitleBarContentProperty);
                    }
                    else
                    {
                        this.SetBinding(DataRow.TitleBarContentProperty, displayMemberBinding);
                    }
                }
            }
        }
Exemple #2
0
        protected virtual void SetTitleBarContentBinding(DataGridContext dataGridContext)
        {
            if (dataGridContext == null)
            {
                return;
            }

            var view = dataGridContext.DataGridControl.GetView();

            if ((view is TableView) || (view is TableflowView))
            {
                return;
            }

            var headerColumn = dataGridContext.Columns.MainColumn as Column;

            if (headerColumn == null)
            {
                return;
            }

            var displayMemberBinding = headerColumn.GetDisplayMemberBinding();

            if (displayMemberBinding == null)
            {
                var dataItem = this.DataContext;
                var itemType = (dataItem != null) ? dataItem.GetType() : null;

                displayMemberBinding = ItemsSourceHelper.CreateDefaultBinding(
                    ItemsSourceHelper.CreateOrGetPropertyDescriptionFromColumn(dataGridContext, headerColumn, itemType));
            }

            if (displayMemberBinding == null)
            {
                Debug.Assert(false, "displayMemberBinding is null.");
                this.ClearValue(DataRow.TitleBarContentProperty);
            }
            else
            {
                this.SetBinding(DataRow.TitleBarContentProperty, displayMemberBinding);
            }
        }