简体   繁体   English

标题上的Silverlight DataGrid添加按钮

[英]Silverlight DataGrid adding button on Header

I have a DataGrid as rowDetailTemplate. 我有一个DataGrid作为rowDetailTemplate。 in this grid I'd like to add a button on header. 在此网格中,我想在标题上添加一个按钮。 I made the following XAML code 我做了以下XAML代码

                          <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. 一切正常,但this列标题。 I am getting System.Windows.DataTemplate instead of the button. 我正在获取System.Windows.DataTemplate而不是按钮。 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 尝试下面的链接,这将帮助您在DataGrid标头中单击Button

Cheers! 干杯! Vinod 维诺德

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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