防止细胞背景在焦点上变白
Preventing cell background from becoming white on focus
我有一个 Xceed 数据网格,其中每个单元格模板都有透明背景。最近我在其中一个单元格模板中放置了一个 ReadOnly TextBox。这允许用户单击单元格和 select 文本的子集。但是,一个副作用是当我单击文本框时单元格变成白色。
这是专栏:
<xcdg:Column Title="{x:Static rcer:CEWR.Field_PinyinDefinition}"
AllowGroup="False"
ReadOnly="True"
CellContentTemplate="{StaticResource ceItemsCellContentTemplate}"
FieldName="Items">
<xcdg:Column.TitleTemplate>
<DataTemplate>
<TextBlock Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Text="{Binding}" />
</DataTemplate>
</xcdg:Column.TitleTemplate>
</xcdg:Column>
和模板
<DataTemplate x:Key="ceItemsCellContentTemplate">
<DataTemplate.Resources />
<ItemsControl Margin="0"
Background="Transparent"
ItemTemplate="{StaticResource ceItemTemplate}"
ItemsSource="{Binding}"
Padding="0"
Style="{StaticResource itemsBoxStyle}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.LayoutTransform>
<ScaleTransform ScaleX="{Binding Zoom, Source={StaticResource ceShowSettings}}" ScaleY="{Binding Zoom, Source={StaticResource ceShowSettings}}" />
</ItemsControl.LayoutTransform>
</ItemsControl>
</DataTemplate>
这里是将单元格背景变白
我试过弄乱 ItemsControl,但事实并非如此。它必须类似于 CellContentStyle - 目前无法访问。
Update. 我可以设置 CanBeCurrentWhenReadOnly="False"
当我单击 TextBox 定义时背景将保留,但我将无法与单元格的内容进行交互。
操作方法如下。
<Style TargetType="{x:Type xcdg:DataCell}">
<Setter Property="CurrentBackground" Value="Transparent"/>
</Style>
我有一个 Xceed 数据网格,其中每个单元格模板都有透明背景。最近我在其中一个单元格模板中放置了一个 ReadOnly TextBox。这允许用户单击单元格和 select 文本的子集。但是,一个副作用是当我单击文本框时单元格变成白色。
这是专栏:
<xcdg:Column Title="{x:Static rcer:CEWR.Field_PinyinDefinition}"
AllowGroup="False"
ReadOnly="True"
CellContentTemplate="{StaticResource ceItemsCellContentTemplate}"
FieldName="Items">
<xcdg:Column.TitleTemplate>
<DataTemplate>
<TextBlock Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" Text="{Binding}" />
</DataTemplate>
</xcdg:Column.TitleTemplate>
</xcdg:Column>
和模板
<DataTemplate x:Key="ceItemsCellContentTemplate">
<DataTemplate.Resources />
<ItemsControl Margin="0"
Background="Transparent"
ItemTemplate="{StaticResource ceItemTemplate}"
ItemsSource="{Binding}"
Padding="0"
Style="{StaticResource itemsBoxStyle}">
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Style.Triggers>
<Trigger Property="IsFocused" Value="True">
</Trigger>
</Style.Triggers>
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.LayoutTransform>
<ScaleTransform ScaleX="{Binding Zoom, Source={StaticResource ceShowSettings}}" ScaleY="{Binding Zoom, Source={StaticResource ceShowSettings}}" />
</ItemsControl.LayoutTransform>
</ItemsControl>
</DataTemplate>
这里是将单元格背景变白
我试过弄乱 ItemsControl,但事实并非如此。它必须类似于 CellContentStyle - 目前无法访问。
Update. 我可以设置 CanBeCurrentWhenReadOnly="False" 当我单击 TextBox 定义时背景将保留,但我将无法与单元格的内容进行交互。
操作方法如下。
<Style TargetType="{x:Type xcdg:DataCell}">
<Setter Property="CurrentBackground" Value="Transparent"/>
</Style>