样式化数据网格中的行

时间:2011-07-13 16:33:43

标签: wpf c#-4.0

在DataGrid中为ItemsSource绑定的行设置样式在哪里?

        

    </DataGrid.Resources>

        <DataGrid.ItemTemplate>
        <DataTemplate>
            <DataTemplate.Resources>

            </DataTemplate.Resources>
        </DataTemplate>

    </DataGrid.ItemTemplate>
        <DataGrid.ContextMenu>
    <ContextMenu>
        <MenuItem Command="{Binding WhitelistAllCommand}" CommandParameter="{Binding SelectedScan.Runs}" Header="Whitelist All" />
        <Separator/>
        <MenuItem  Header="Copy Cell" ItemsSource="{Binding Properties}" IsCheckable="False">
            <MenuItem.ItemTemplate>
                <DataTemplate>
                    <MenuItem Command="{Binding DataContext.CopyDatumCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding .}" Header="{Binding Name}" />
                </DataTemplate>
            </MenuItem.ItemTemplate>
        </MenuItem>
        <MenuItem Header="Copy Table" Command="{Binding CopyDataCommand}" />
    </ContextMenu>
</DataGrid.ContextMenu>

<DataGrid.Columns>
    <DataGridTemplateColumn Header="Commands">
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal">
                    <Button Content="Whitelist" Padding="0,-2,0,-2" Margin="0" Command="{Binding DataContext.TableFilterViewModel.AddWhitelistItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}}" CommandParameter="{Binding .}" />
                    <Button Content="{x:Static Properties:Resources.OpenShare}" Command="{Binding DataContext.GrabFileCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" CommandParameter="{Binding .}" Padding="-2" Margin="0" />
                </StackPanel>
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    <DataGridTextColumn Width="200" Binding="{Binding Name}" Header="Program"/>
    <DataGridTextColumn Width="450" Binding="{Binding Value}" Header="Location"/>

</DataGrid.Columns>

1 个答案:

答案 0 :(得分:0)

您必须使用DataGrid.RowStyle