我在我的 WPF GUI 中使用資料網格,用戶可以在其中雙擊一行以查看包含詳細資訊的頁面(這很好用):

不幸的是,在連續單擊(一次)后,單個單元格的邊框將可見,盡管我已經在使用 selection unit FullRow。我嘗試了不同的選項、顏色等,但每次顯示邊框。我正在嘗試如何抑制 DataGrid 單元格選擇中的步驟,但它只是改變了 datagrid 樣式。
<DataGrid x:Name="DataGridMeasuringTasks" SelectionUnit="FullRow" Margin="20,145,0,44"
RowDetailsVisibilityMode="VisibleWhenSelected" CanUserAddRows="False"
CanUserDeleteRows="False" HorizontalAlignment="Left" Width="1612"
SelectionMode="Single" IsReadOnly="True">
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="#FFF0F0F0" />
</Style>
</DataGrid.RowStyle>
<DataGrid.Background>
<SolidColorBrush Color="#FFF0F0F0"/>
</DataGrid.Background>
</DataGrid>
如何洗掉邊框?
uj5u.com熱心網友回復:
資料網格單元格的 MaterialDesign 樣式在此處定義。您必須復制和調整樣式,因為邊框畫筆的觸發器將優先于本地值。洗掉這部分。
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource MaterialDesignTextBoxBorder}" />
</Trigger>
然后,將樣式分配CellStyle給您的特定樣式DataGrid或將其移動到范圍內的資源字典甚至應用程式資源,以自動將樣式應用于范圍內的所有單元格。
<DataGrid x:Name="DataGridMeasuringTasks" SelectionUnit="FullRow" Margin="20,145,0,44"
RowDetailsVisibilityMode="VisibleWhenSelected" CanUserAddRows="False"
CanUserDeleteRows="False" HorizontalAlignment="Left" Width="1612"
SelectionMode="Single" IsReadOnly="True">
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(materialDesign:DataGridAssist.CellPadding)}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
<Setter Property="Foreground" Value="{Binding Foreground, RelativeSource={RelativeSource AncestorType=DataGridRow}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid>
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True" />
<ContentPresenter Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="True" />
<Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType=DataGridRow}}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="{DynamicResource MaterialDesignSelection}" />
</MultiDataTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value=".56" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="#FFF0F0F0" />
</Style>
</DataGrid.RowStyle>
<DataGrid.Background>
<SolidColorBrush Color="#FFF0F0F0"/>
</DataGrid.Background>
</DataGrid>
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/430525.html
標籤:。网 wpf xml 数据网格 xaml 中的材料设计
