예제 #1
0
        private void CustomDataGridLoaded(object sender, RoutedEventArgs e)
        {
            var panel = Helper.GetVisualChild <CustomDataGridRowsPresenter>(this);

            if (panel != null)
            {
                panel.InvalidateArrange();
            }
            var extendedDataGrid = this as ExtendedDataGrid;

            if (extendedDataGrid != null && extendedDataGrid.FrozenRowCount != 0)
            {
                PropertyMetadata stye      = DefaultStyleKeyProperty.GetMetadata(typeof(CustomDataGrid));
                Type             ownerType = typeof(CustomDataGrid);
                if (((Type)(stye.DefaultValue)).Name == "DataGrid")
                {
                    DefaultStyleKeyProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(ownerType));
                }

                stye = ItemsPanelProperty.GetMetadata(ownerType);

                if (((FrameworkTemplate)(stye.DefaultValue)).VisualTree.Type != typeof(CustomDataGridRowsPresenter))
                {
                    ItemsPanelProperty.OverrideMetadata(ownerType,
                                                        new FrameworkPropertyMetadata(
                                                            new ItemsPanelTemplate(
                                                                new FrameworkElementFactory(
                                                                    typeof(CustomDataGridRowsPresenter)))));
                }
            }
            if (panel != null)
            {
                panel.InvalidateArrange();
            }
        }
        /// <summary>
        /// Property changed callback fro FrozenRowCount
        /// </summary>
        /// <param name="d"></param>
        /// <param name="e"></param>
        private static void OnFrozenRowCountPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var extendedDataGrid = d as ExtendedDataGrid;

            if (extendedDataGrid != null && extendedDataGrid.FrozenRowCount == 0)
            {
                return;
            }

            var panel = Helper.GetVisualChild <CustomDataGridRowsPresenter>(d as Visual);

            if (panel != null)
            {
                panel.InvalidateArrange();
            }
            else
            {
                PropertyMetadata style     = DefaultStyleKeyProperty.GetMetadata(typeof(CustomDg));
                Type             ownerType = typeof(CustomDg);
                if (((Type)(style.DefaultValue)).Name == "DataGrid")
                {
                    DefaultStyleKeyProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(ownerType));
                }

                style = ItemsPanelProperty.GetMetadata(ownerType);

                if (((FrameworkTemplate)(style.DefaultValue)).VisualTree.Type != typeof(CustomDataGridRowsPresenter))
                {
                    ItemsPanelProperty.OverrideMetadata(ownerType,
                                                        new FrameworkPropertyMetadata(
                                                            new ItemsPanelTemplate(
                                                                new FrameworkElementFactory(
                                                                    typeof(CustomDataGridRowsPresenter)))));
                }
                panel = Helper.GetVisualChild <CustomDataGridRowsPresenter>(d as Visual);
                if (panel != null)
                {
                    panel.InvalidateArrange();
                }
            }
            var dataGrid = d as DataGrid;

            if (dataGrid != null)
            {
                try
                {
                    dataGrid.UpdateLayout();
                }
                catch
                {
                }
            }

            if (panel != null)
            {
                panel.InvalidateArrange();
            }
        }
예제 #3
0
 public StyleTabControl()
 {
     Assert.AreEqual(DefaultStyleKey, typeof(TabControl), "1");
     Assert.AreSame(DefaultStyleKeyProperty.GetMetadata(this), DefaultStyleKeyProperty.GetMetadata(typeof(TabControl)), "2");
 }