【问题标题】:How to inherit default textbox style in wpf datagrid?如何在 wpf 数据网格中继承默认文本框样式?
【发布时间】:2013-07-17 02:45:30
【问题描述】:

我在wpf dataGrid中有一个TextBox DataGridTemplateColumn .it不会继承DataGrid本身的外观。已编辑。

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

看起来默认文本框的样式覆盖了DataGrid 的样式。有没有办法使用数据网格样式?

【问题讨论】:

  • TextBox默认是什么风格?你的风格或系统?
  • 我不明白你的意思,DataGridTemplateColumn 中的文本框应该与 DataGridTextColumn 中的文本框具有相同的样式。
  • 不,不应该。当您在DataTemplate 中指定强制TextBox 时,您会自动覆盖DataGrid 的默认DataGridCell 样式。您需要为DataGridCell 建立一个样式,然后TextBox 将是一个样式(在DataGridTemplateColumnDataGridTextColumn 中)。为DataGridCell 设置统一样式时,仍然需要为DataGridRow 设置样式,因为选择行不起作用。无论如何,最好为DataGrid 取一个预定义的样式,然后自己重​​新制作。

标签: wpf styles wpfdatagrid


【解决方案1】:

以防万一:-

 <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>

这是我使用的,一旦你可以根据你的要求设置属性。

这可能会有所帮助..:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 2011-07-15
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多