0

I have a DataGrid as rowDetailTemplate. in this grid I'd like to add a button on header. I made the following XAML code

                          <sdk:DataGridTemplateColumn   >
                                        <sdk:DataGridTemplateColumn.Header>
                                            <DataTemplate>
                                                <Button Content="Row" Height="23" HorizontalAlignment="Left"  VerticalAlignment="Top" Width="30" />
                                            </DataTemplate>
                                        </sdk:DataGridTemplateColumn.Header>
                                         <sdk:DataGridTemplateColumn.CellTemplate>
                                            <DataTemplate>
                                                <Button Content="Del"></Button>
                                            </DataTemplate>
                                        </sdk:DataGridTemplateColumn.CellTemplate>
                                    </sdk:DataGridTemplateColumn>

Everything works correctly but the this column header. I am getting System.Windows.DataTemplate instead of the button. What am i doing wrong?

2 Answers 2

1

Finally i found the way by compiling some answers. the following will add a template column with header-Body containing controls:

     <sdk:DataGridTemplateColumn >
          <sdk:DataGridTemplateColumn.HeaderStyle>
              <Style TargetType="sdk:DataGridColumnHeader">
                  <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                  <Button Content="Row" />
                             </DataTemplate>
                         </Setter.Value>
                  </Setter>
              </Style>
          </sdk:DataGridTemplateColumn.HeaderStyle>
          <sdk:DataGridTemplateColumn.CellTemplate>
              <DataTemplate>
                 <Button Content="Del"  ></Button>
              </DataTemplate>
          </sdk:DataGridTemplateColumn.CellTemplate>
        </sdk:DataGridTemplateColumn>
Sign up to request clarification or add additional context in comments.

Comments

0

Try this below link which will help you Button in DataGrid header

Cheers! Vinod

1 Comment

Thanks Vinod, but I don't want use style. I want to just add a template header, and CellTemplate, and why my code is not working. thanks anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.