【发布时间】:2016-02-11 05:49:44
【问题描述】:
我在 DataGrid 中遇到 TextBlock 的问题。
我无法禁用 TextBlock 的 Border。
对于 TextBlock,没有名称为 BorderThickness 的 No Property。
那么我们如何禁用 TextBlock 的边框。
我在这里添加我的示例网格单元格样式
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="DarkTurquoise" />
<Setter Property="IsSelected" Value="True"/>
<Setter Property="BorderThickness" Value="0"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
我在这里添加我的整个 DataGrid 代码
<DataGrid Name="gridcancelled" ItemsSource="{Binding}" HeadersVisibility="None" IsReadOnly="True" AutoGenerateColumns="False" GridLinesVisibility="Horizontal" Background="White" Cursor="Hand" MouseLeftButtonDown="gridcancelled_MouseLeftButton" Loaded="gridcancelled_Loaded" PreviewKeyDown="gridcancelled_PreviewKeyDown" RowHeight="44.9" SelectedIndex="0" HorizontalGridLinesBrush="{StaticResource BlueGridLine}" VerticalGridLinesBrush="{StaticResource BlueGridLine}" BorderThickness="1.5,1,1,1" BorderBrush="Gray">
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="DarkTurquoise" />
<Setter Property="IsSelected" Value="True"/>
<Setter Property="BorderThickness" Value="0"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="DarkTurquoise"/>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="DarkTurquoise" />
<Setter Property="FontSize" Value="14"></Setter>
<Setter Property="FontWeight" Value="Medium"></Setter>
</Trigger>
<Trigger Property="DataGridRow.IsSelected" Value="True">
<Setter Property="Foreground" Value="White" />
<Setter Property="Background" Value="DarkTurquoise" />
<Setter Property="FontSize" Value="14"></Setter>
<Setter Property="FontWeight" Value="Medium"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding billId}" Width="220">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding billDate}" Width="210" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding counterId}" Width="210">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding cashierId}" Width="190" >
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding dueAmount, StringFormat={}{0:0.00}}" Width="172">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Margin" Value="0,0,60,0"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
我在这里添加我的 PreviewKeyDown 事件代码
private void gridcancelled_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Up)
{
e.Handled = true;
if (gridcancelled.SelectedIndex == 0)
{
gridcancelled.SelectedIndex = gridcancelled.Items.Count - 1;
}
else
{
gridcancelled.SelectedIndex--;
}
}
if (e.Key == Key.Down)
{
e.Handled = true;
if (gridcancelled.Items.Count - 1 > gridcancelled.SelectedIndex)
{
gridcancelled.SelectedIndex++;
}
else if (gridcancelled.SelectedIndex == gridcancelled.Items.Count - 1)
{
gridcancelled.SelectedIndex = 0;
}
}
}
请给我你的建议。
提前致谢。
【问题讨论】:
-
给出你的数据网格代码。我会编辑的。
-
感谢您的回复@KyloRen 请检查我已添加示例代码...
-
你是指单元格聚焦时显示的边框吗?
-
屏幕截图中的边框在哪里? @sagar
-
请检查我添加了 GUI ...我的问题是我为我的网格提供导航。当我移动上下箭头时,我没有获得下一行的焦点 @safi