简体   繁体   中英

Silverlight DataGrid adding button on Header

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?

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>

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

Cheers! Vinod

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM