开发者

Adding a row of controls in a Silverlight Datagrid

开发者 https://www.devze.com 2023-03-12 01:25 出处:网络
In the application I\'m developing, I\'m using a datagrid to display data fetch from a database. It is declared like so in my XAML file:

In the application I'm developing, I'm using a datagrid to display data fetch from a database. It is declared like so in my XAML file:

<sdk:DataGrid x:Name="dg" AutoGenerateColumns="False" ItemSource={Binding etc.} >
    <sdk:DataGrid.Columns>
        <sdk:DataGridTextBoxColumn Header="Col1"
             Binding="{Binding Col1Data}" />
        <sdk:DataGridTextBoxColumn Header="Col2" 
             Binding="{Binding Col2Data}" />
        <sdk:DataGridTextBoxColumn Header="Col3"
             Binding="{Binding Col3Data}" />
        <sdk:DataGridCheckBoxColumn Header="Col4" 
             Binding="{Binding Col4Data}" />
   <sdk:DataGrid.Columns>
<sdk:DataGrid>

What I want to do, is to add a row, containing 5 combo boxes (1 for each column) between the header and the first row of my data.开发者_开发问答 It is pretty easy to do for a column, using DataGridTemplateColumn, but how can I do this for a row?

Thanks in advance for your suggestions!

Fake edit: Oh by the way I'm not a fan of code behind (trying to go full MVVM), so I'm looking for a way to do this in XAML, if possible.


You may be able to get away with providing a template for the header, but failing that you'll need to re-template the DataGrid in order to do this.


Ok, so I kinda found a work around. I declared a template for my cells that contains a button and a textblock bound to the data. i bind the visibility property of the button on a boolean that will be true only for the elements of the first row.

<sdk:DataGridTemplateColumn Header="Col1" Width="60">
    <sdk:DataGridTemplateColumn.CellTemplate>
       <DataTemplate>
          <StackPanel Orientation="Vertical" Height="30">
             <Button Content="Boutton" Visibility="{Binding Path=IsFirstElement, Converter={StaticResource visibilityConverter}}" />
             <TextBlock Text="{Binding Path=Col1Data}" />
           </StackPanel>
        </DataTemplate>
     </sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>

It's a bit hack-ish. But it works. My only concern is performance since a button is declared for each cell. So with thousands of row, I guess there could be a performance hit.

0

精彩评论

暂无评论...
验证码 换一张
取 消