简体   繁体   中英

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?

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 ..:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM