DataGridTextColumn header binding

Dec 20, 2009 at 3:38 PM

I want to dynamically update/set the DataGridTextColumn header based on variable array in my code behind.

In my code behind.

        private List<int> years;
        public List<int> Years
        {
            get
            {
                return years;
            }
            set
            {
                years = value;
                RaisePropertyChanged("Years");
            }
        }


in my xaml file I have a datagrid, where I want to set the header on a column
            <toolkit:DataGrid ItemsSource="{Binding Prices}">
                <toolkit:DataGrid.Columns>
                    <toolkit:DataGridTextColumn Binding="{Binding Gloves}">
                        <toolkit:DataGridTextColumn.Header>
                            <Label Content="{Binding Years[0]}"/>
                        </toolkit:DataGridTextColumn.Header>
                    </toolkit:DataGridTextColumn>
                </toolkit:DataGrid.Columns>
            </toolkit:DataGrid>


It doesn't seem to work, the header is empty (nothing is shown)
 - If I change Content="{Binding Years[0]}" to Content="2010" then the header shows 2010

 

Any help is appreciated.

thx in advance