我面臨着一個問題TextBlock in DataGrid。 我無法禁用邊框對於TextBlock。 還有沒有物業與名稱BorderThickness對於TextBlock。
那麼我們怎樣才能禁用一個TextBlock的邊框。如何禁用WPF數據網格中的文本塊邊界?
在這裏,我將我的樣本網格單元格樣式
<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
您的意思是單元格聚焦時顯示的邊框? – safi