user145610
user145610

Reputation: 3025

How to have style applied for wpf datagrid row

I am Having requirement on WPF Datagrid row,Whenever user selects a DatagridRow,corresponding datagrid Cells borders should have thickness of 1 or 2 .

or Provide margin for textboxes/Textblocks within in DatagridCell.

With regards, Mahens

Upvotes: 0

Views: 1578

Answers (1)

Mark Synowiec
Mark Synowiec

Reputation: 5445

I'm not sure if this is exactly what you're looking for, but here's an example of modifying the default listboxitem style for a gridview (NOTE the top level Grid is the top-level element in a xaml file):

    <Grid>
        <Grid.Resources>
            <Style x:Key="itemstyle" TargetType="{x:Type ListBoxItem}">
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="BorderThickness" Value="3"/>
                        <Setter Property="BorderBrush" Value="Black"/>
                    </Trigger>
                </Style.Triggers>
            </Style>
        </Grid.Resources>
        <ListView Name="grid" ItemContainerStyle="{StaticResource itemstyle}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
                    <GridViewColumn Header="Age" DisplayMemberBinding="{Binding Path=Age}"/>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>

I just created a generic Person type with a Name string property and an int Age property. I added a few of these to a list and set the ItemsSource of grid to the List.

Upvotes: 2

Related Questions