views:

286

answers:

1

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

I have created a child class that derives from ProductionDataUserControlBase and it does contain XAML. In the property editor of the inherited control my Columns collection exists. I can open the collection through the property editor and add new columns. However, the columns editor does not contain the columns that I added in the base even though I can visually see the columns on the canvas.

I'm assuming this is because the columns that I added in the base are not in the XAML of the child. If I add the columns through XAML of the child it creates duplicate columns because they were added in the base. How can I edit the property of the columns that were added in the base without using code-behind in the 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's 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"&gt;

    </ProductionDataUserControlBase>

public partial class AmerenProductionDataUserControl : ProductionDataUserControlBase
        {

            public AmerenProductionDataUserControl()
            {
                InitializeComponent();                                            
            }
        }
A: 

Sounds like you either overrid the contents of the collection or overrode the property.

Danny Varod
Thanks for the response but maybe you could explain further. Your response suggests that I overrode a property from--I'm assuming you mean the grid--but in the code above, it shows that I only expose the column property because I'm not inheriting from the grid but from user control. Because I'm inheriting from user control and not the grid, it would be impossible to override the column collection from the grid.
Brian