mahboub_mo
mahboub_mo

Reputation: 3038

How to inherit default textbox style in wpf datagrid?

I have a TextBox in a DataGridTemplateColumn in a WPF datagrid.It doesn't inherit the look and feel of the datagrid itself.For example it doesn't show the alternating color, when a row is selected or edited.

       <DataGridTemplateColumn>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding ...}" />                          
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

It looks like the style of a default textbox overrides that of the DataGrid.Is there any way to use the datagrids style?

Upvotes: 0

Views: 1126

Answers (1)

Vishal
Vishal

Reputation: 624

Just in case:-

 <DataGrid Background="White" AlternatingRowBackground="#BCD2EE"
        <DataGrid.CellStyle>
                            <Style TargetType="DataGridCell">
                                <Style.Triggers>
                                    <Trigger Property="IsSelected" Value="True">
                                        <Setter Property="BorderBrush" Value="Transparent" />
                                        <Setter Property="Background" Value="Transparent" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.CellStyle>
....
.....
....
    </DataGrid>

This is what I used once you can set property according to your requirements.

This Might help ..:)

Upvotes: 1

Related Questions