Ejemplo n.º 1
0
        private static void ParentGridControlPropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            DataGridControl oldParentGridControl = e.OldValue as DataGridControl;
            DataGridControl parentGridControl    = e.NewValue as DataGridControl;
            ScrollTip       scrollTip            = sender as ScrollTip;

            scrollTip.IsInParentGridChanged = true;
            try
            {
                if (oldParentGridControl != null)
                {
                    if (scrollTip.UsingDefaultScrollTipContentTemplate)
                    {
                        // Unload DefaultTemplate
                        Nequeo.Wpf.DataGrid.Views.UIViewBase uiViewBase = oldParentGridControl.GetView() as Nequeo.Wpf.DataGrid.Views.UIViewBase;

                        if (uiViewBase != null)
                        {
                            uiViewBase.ClearValue(UIViewBase.ScrollTipContentTemplateProperty);
                            scrollTip.UsingDefaultScrollTipContentTemplate = false;
                        }
                    }

                    if (scrollTip.m_mainColumn != null)
                    {
                        PropertyChangedEventManager.RemoveListener(scrollTip.m_mainColumn, scrollTip, "DisplayMemberBinding");
                    }

                    scrollTip.m_mainColumn = null;

                    scrollTip.UnregisterListeners(oldParentGridControl);
                }

                if (parentGridControl == null)
                {
                    return;
                }

                scrollTip.PrepareDefaultStyleKey(parentGridControl.GetView());

                // Assert Template is applied in order to be notified for ScrollBars events
                DataGridControl.SetDataGridContext(scrollTip, parentGridControl.DataGridContext);

                if (!scrollTip.ApplyTemplate())
                {
                    scrollTip.RefreshDefaultScrollTipContentTemplate();
                }

                scrollTip.RegisterListeners(parentGridControl);
            }
            finally
            {
                scrollTip.IsInParentGridChanged = false;
            }
        }
Ejemplo n.º 2
0
        private void RefreshDefaultScrollTipContentTemplate()
        {
            DataGridContext itemContext = DataGridControl.GetDataGridContext(this);

            if (itemContext == null)
            {
                return;
            }

            DataGridControl parentGridControl = itemContext.DataGridControl;

            if ((parentGridControl == null) || (parentGridControl.ScrollViewer == null))
            {
                return;
            }

            ColumnCollection columnCollection = itemContext.Columns;

            if (columnCollection == null)
            {
                return;
            }

            Column mainColumn = columnCollection.MainColumn as Column;

            if (mainColumn == null)
            {
                return;
            }

            Nequeo.Wpf.DataGrid.Views.UIViewBase uiViewBase = parentGridControl.GetView() as Nequeo.Wpf.DataGrid.Views.UIViewBase;

            if (uiViewBase == null)
            {
                return;
            }

            // The ScrollTip.ContentTemplate will now be set. This is to avoid
            // a null ContentTemplate when the ColumnsCollection update its
            // MainColumn after the template is applied
            this.ScrollTipContentTemplateNeedsRefresh = false;

            ForeignKeyConfiguration configuration = mainColumn.ForeignKeyConfiguration;

            // Do not create default template only when none was created before and a template already exists
            if ((!this.UsingDefaultScrollTipContentTemplate) && (uiViewBase.ScrollTipContentTemplate != null))
            {
                if (configuration != null)
                {
                    this.ContentTemplate = configuration.DefaultScrollTipContentTemplate;
                }
                else
                {
                    // Clear the value in case we previously affected it
                    this.ClearValue(ScrollTip.ContentTemplateProperty);

                    // Set the default Binding values
                    this.SetBinding(ScrollTip.ContentTemplateProperty, this.DefaultScrollTipContentTemplateBinding);
                    this.SetBinding(ScrollTip.ContentTemplateSelectorProperty, this.DefaultScrollTipContentTemplateSelectorBinding);
                }
            }
            else
            {
                // A default ContentTemplate template is created using MainColumn as displayed data
                this.UsingDefaultScrollTipContentTemplate = true;

                // If a configuration was found, the default ContentTemplate will
                // be used to convert Content to Foreign value and
                // it will use the ScrollTipContentTemplate defined on UIViewBase
                // if any
                if (configuration == null)
                {
                    // Disable warning for DisplayMemberBinding when internaly used
#pragma warning disable 618

                    BindingBase displayMemberBinding = mainColumn.DisplayMemberBinding;

#pragma warning restore 618

                    FrameworkElementFactory contentPresenter = new FrameworkElementFactory(typeof(ContentPresenter));
                    contentPresenter.SetValue(ContentPresenter.NameProperty, "defaultScrollTipDataTemplateContentPresenter");
                    contentPresenter.SetBinding(ContentPresenter.ContentProperty, displayMemberBinding);

                    contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, this.DefaultCellContentTemplateBinding);
                    contentPresenter.SetBinding(ContentPresenter.ContentTemplateSelectorProperty, this.DefaultCellContentTemplateSelectorBinding);

                    DataTemplate template = new DataTemplate();
                    template.VisualTree = contentPresenter;
                    template.Seal();

                    this.ContentTemplate = template;
                }
                else
                {
                    this.SetBinding(ContentPresenter.ContentTemplateProperty, this.DefaultCellContentTemplateBinding);
                    this.SetBinding(ContentPresenter.ContentTemplateSelectorProperty, this.DefaultCellContentTemplateSelectorBinding);
                    this.ContentTemplate = configuration.DefaultScrollTipContentTemplate;
                }
            }
        }