gpt4 book ai didi

wpf - 奇怪的 WPF DataGrid 行为 : Little button like nubbies indenting some rows appearing to the left of the first column

转载 作者:行者123 更新时间:2023-12-05 01:20:22 24 4
gpt4 key购买 nike

我将 DataGrid 绑定(bind)到自定义对象的 ObservableCollection。间歇性地,我得到(可能在 2 或 3 行上)一个按钮,如 nubbie 对象(大约 4 像素宽和行的高度)出现在左边缘,并导致该行的列略微缩进,以便它们不会t 排队。我不认为这些行有什么特别之处,因为如果我将网格重新绑定(bind)到相同的对象,小块可能根本不会发生或可能出现在不同的行上。

我正在使用一些自定义样式,并且我的第一列是 DataTemplate,因此我将其包含在下面,以防任何人都可以看到其中可能导致我的问题的任何内容。在这一点上我有点难过...

<DataGrid  Style="{DynamicResource WPFDataGridStyle}" Background="White" BorderBrush="LightGray" FontSize="13"
CanUserReorderColumns="True" HorizontalGridLinesBrush="#FFEFEFEF" VerticalGridLinesBrush="#FFEFEFEF" HeadersVisibility="Column"
AlternatingRowBackground="#FFF4F4F4" CanUserResizeRows="False" SelectionMode="Single" AutoGenerateColumns="False"
CanUserAddRows="False" CanUserDeleteRows="False" CanUserSortColumns="True" FrozenColumnCount="3"
ItemsSource="{Binding VM.FilteredSteamJobs,Mode=TwoWay,Source={StaticResource VM}}"
SelectedItem="{Binding VM.SelectedJob,Mode=TwoWay,Source={StaticResource VM}}"
Visibility="{Binding VM.IsScheduleLoaded,Mode=OneWay,Source={StaticResource VM},Converter={StaticResource BoolToVisConv}}" >
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#AAA7CDF0"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#AAA7CDF0"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlTextBrushKey}" Color="Black"/>

<Style x:Key="WPFDataGridStyle" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource {x:Type DataGrid}}">
<Setter Property="ColumnHeaderStyle" Value="{DynamicResource ColumnHeaderStyle1}"/>
<Setter Property="CellStyle" Value="{DynamicResource CellStyle1}"/>
</Style>

<Style x:Key="ColumnHeaderStyle1" TargetType="DataGridColumnHeader" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}">
<Setter Property="Height" Value="25"/>
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FFC8E0FF" Offset="1"/>
<GradientStop Color="#FFF5FAFF" Offset="0"/>
<GradientStop Color="#FFDBEBFF" Offset="0.5"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="Padding" Value="3"/>
<Setter Property="BorderThickness" Value="0.5,0"/>
<Setter Property="BorderBrush" Value="DarkGray"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontSize" Value="13" />
</Style>

<Style x:Key="CellStyle1" TargetType="{x:Type DataGridCell}">
<Setter Property="Height" Value="25"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FontSize" Value="13"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Padding" Value="3,0"/>
</Style>
</DataGrid.Resources>

<DataGrid.Columns>

<!--Selection Checkbox Column-->
<DataGridTemplateColumn IsReadOnly="True" CanUserResize="False" CanUserSort="False" Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<CheckBox VerticalAlignment="Center" HorizontalAlignment="Center" Margin="3"
IsChecked="{Binding Path=IsSelected,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
Visibility="{Binding Status,Converter={StaticResource StatusToSelectVisConv}}">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="1.2" ScaleY="1.2"/>
</CheckBox.LayoutTransform>
</CheckBox>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.HeaderTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox VerticalAlignment="Center" Checked="HeaderSelect_Checked" Unchecked="HeaderSelect_Unchecked">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="1.3" ScaleY="1.3"/>
</CheckBox.LayoutTransform>
</CheckBox>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.HeaderTemplate>
</DataGridTemplateColumn>

最佳答案

我也一直在努力解决这个问题,如果我没记错你必须设置 RowHeaderWidth="0"在 DataGrid 上以避免此“错误”。

显然,某些随机行的行标题显示,即使 HeadersVisibility设置为 Column .

关于wpf - 奇怪的 WPF DataGrid 行为 : Little button like nubbies indenting some rows appearing to the left of the first column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13383046/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com