开发者

Style rows in a datagrid

Where do you set styles for rows in a DataGrid that is bound to an 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>

<Data开发者_Go百科Grid.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>


You have to use DataGrid.RowStyle.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜