This is a migrated thread and some comments may be shown as answers.

[Solved] Add textblock to Column Header

2 Answers 159 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Zied
Top achievements
Rank 1
Zied asked on 20 Jan 2014, 10:59 AM
Hello, is there any way that i can add a text block under the column header which i have like this :
  <Grid:RadDataGrid Background="White" AutoGenerateColumns="False"  Foreground="#2582d3"   BorderBrush="#2582d3"     HorizontalAlignment="Left" Height="463"  x:Name="DataGrid" VerticalAlignment="Top" GridLinesBrush="#2582d3" Margin="10,199,0,0" Width="1346" >

                <Grid:DataGridTextColumn PropertyName="DateLundi" Header="Lundi" >
                <Grid:DataGridTextColumn.HeaderStyle>
                <Style TargetType="gridPrimitives:DataGridColumnHeader">
                <Setter Property="Background" Value="#2582d3"/>
                            
                        </Style>
                            
                </Grid:DataGridTextColumn.HeaderStyle>
                    
                </Grid:DataGridTextColumn>
                <Grid:DataGridTextColumn PropertyName="Mardi">
                <Grid:DataGridTextColumn.HeaderStyle>
                <Style TargetType="gridPrimitives:DataGridColumnHeader">
                <Setter Property="Background" Value="#2582d3"/>
                </Style>
                </Grid:DataGridTextColumn.HeaderStyle>
                </Grid:DataGridTextColumn>
                <Grid:DataGridTextColumn PropertyName="Mercredi">
                <Grid:DataGridTextColumn.HeaderStyle>
                <Style TargetType="gridPrimitives:DataGridColumnHeader">
                <Setter Property="Background" Value="#2582d3"/>
                </Style>
                </Grid:DataGridTextColumn.HeaderStyle>
                </Grid:DataGridTextColumn>
                <Grid:DataGridTextColumn PropertyName="Jeudi">
                <Grid:DataGridTextColumn.HeaderStyle>
                <Style TargetType="gridPrimitives:DataGridColumnHeader">
                <Setter Property="Background" Value="#2582d3"/>
                </Style>
                </Grid:DataGridTextColumn.HeaderStyle>
                </Grid:DataGridTextColumn>
                <Grid:DataGridTextColumn PropertyName="Vendredi">
                <Grid:DataGridTextColumn.HeaderStyle>
                <Style TargetType="gridPrimitives:DataGridColumnHeader">
                <Setter Property="Background" Value="#2582d3"/>
                </Style>
                </Grid:DataGridTextColumn.HeaderStyle>
                </Grid:DataGridTextColumn>
                <Grid:DataGridTextColumn PropertyName="Samedi">
                <Grid:DataGridTextColumn.HeaderStyle>
                <Style TargetType="gridPrimitives:DataGridColumnHeader">
                <Setter Property="Background" Value="#2582d3"/>
                </Style>
                </Grid:DataGridTextColumn.HeaderStyle>
                </Grid:DataGridTextColumn>
                <Grid:DataGridTextColumn PropertyName="Dimanche">
                <Grid:DataGridTextColumn.HeaderStyle>
                <Style TargetType="gridPrimitives:DataGridColumnHeader">
                <Setter Property="Background" Value="#2582d3"/>
                </Style>
                </Grid:DataGridTextColumn.HeaderStyle>
                </Grid:DataGridTextColumn>
                </Grid:RadDataGrid.Columns>

            </Grid:RadDataGrid>



the problem is that i want to add a date under every day for example just under "Lundi" i want to add a date ..in fact i want to add a textblock which will contain the selectedvalue of raddatePicker !
any ideas please ? thx :)

2 Answers, 1 is accepted

Sort by
0
Zied
Top achievements
Rank 1
answered on 20 Jan 2014, 10:28 PM
Hello, i did something like this 
  <Grid:DataGridTextColumn PropertyName="Lundi"  >
                <Grid:DataGridTextColumn.HeaderStyle>
                <Style TargetType="gridPrimitives:DataGridColumnHeader">
                <Setter Property="Background" Value="#2582d3"/>
                           
                        </Style>
                            
                </Grid:DataGridTextColumn.HeaderStyle>
                    <Grid:DataGridTextColumn.Header>
                        <TextBlock  >
                            <TextBlock.Inlines>
                              <Run Text="Lundi"/>
                                <LineBreak/>
                                <Run Text="16/09/13"/>
                            </TextBlock.Inlines>
                        </TextBlock>


this works fine but i want to bind the date value to the selected value in a raddatepicker any ideas please i'm stuck here !
                       
                    </Grid:DataGridTextColumn.Header>
                </Grid:DataGridTextColumn>
0
Rosy Topchiyska
Telerik team
answered on 22 Jan 2014, 02:27 PM

Hi Zied,

Thank you for the question.

Generally, you would be able bind the TextBlock.Text property in the column header to the RadDatePicker.Value property via ElementName binding. Unfortunately, the current version of the grid has a layout issue when you change the text of the header.

As a workaround, in the case when you use a TextBlock as a header, if you wish to change the text, then you have to:

  1. reset the TextBlock.Text property;
  2. call the TextBlock.UpdateLayout() method;
  3. set the TextBlock.Text property to the desired value.

In your case you can use the RadDatePicker.ValueChanged event and set the TextBlock.Text to the RadDatePicker.Value. I have attached a sample application to demonstrate how to do that.

I hope his helps.

Regards,
Rositsa Topchiyska
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Grid for XAML
Asked by
Zied
Top achievements
Rank 1
Answers by
Zied
Top achievements
Rank 1
Rosy Topchiyska
Telerik team
Share this question
or