WPF: How to change base / parent class column properties in child class via property / XAML editor?

I created a class called ProductionDataUserControlBase and it comes from the UserControl class. This base class has no XAML. Its purpose is to act as a base class for the grid, which I encapsulate inside the class so that it can be changed when the class is inherited later. Inside the base class constructor, I also create columns and add them to the Grid collection. I created a public property called columns and all it does is return (get) a collection of grid column properties.

I created a child class that comes from ProductionDataUserControlBase and contains XAML. There is a Columns collection in the property editor of the inherited control. I can open the collection through the property editor and add new columns. However, the column editor does not contain the columns that I added to the base, although I can visually see the columns on the canvas.

I assume this is because the columns I added in the base are not part of the XAML of the child. If I add columns through the XAML of the child, it creates duplicate columns because they were added to the base. How to change property of columns added to base without using code in child?

public partial class ProductionDataUserControlBase : UserControl
    {
        private RadGridView _grdProdData;
        private Boolean _InitCalled = false; //Boolean variable used to control whether init was previously called.
        //This is because the loaded event may be fired multiple times depending
        //on what type of control it been placed into.

        public ProductionDataUserControlBase()
        {
            InitializeComponent();
        }        


        public Telerik.Windows.Controls.GridViewColumnCollection Columns
        {
            get
            {
                return _grdProdData.Columns;            
            }            
        }        

        protected virtual void InitializeComponent()
        {
            if (!_InitCalled)
            {                
                InitializeGrid();
                Columns = _grdProdData.Columns;
                this.AddChild(_grdProdData);                                                

                _InitCalled = true;
            }
        }

        private void InitializeGrid()
        {
            Telerik.Windows.Controls.GridViewColumn grdCol = null;

            this._grdProdData = new RadGridView();
            this._grdProdData.AutoGenerateColumns = false;

            grdCol = new Telerik.Windows.Controls.GridViewColumn() { HeaderText = "PSTAT", Name = "grdColPSTAT", UniqueName = "PSTAT" };
            _grdProdData.Columns.Add(grdCol);

            grdCol = new Telerik.Windows.Controls.GridViewColumn() { HeaderText = "PCONO", Name = "grdColPCONO", UniqueName = "PCONO" };
            _grdProdData.Columns.Add(grdCol);

         }

    }

<ProductionDataUserControlBase x:Class="AmerenProductionDataUserControl"    
            xmlns:MSControls="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns="clr-namespace:AmerenProductionDataUserControl;assembly=AmerenProductionDataUserControl" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">

    </ProductionDataUserControlBase>

public partial class AmerenProductionDataUserControl : ProductionDataUserControlBase
        {

            public AmerenProductionDataUserControl()
            {
                InitializeComponent();                                            
            }
        }

      

+2


source to share


1 answer


It looks like you have either overridden the contents of the collection or overridden the property.



0


source







All Articles