我可以在例如Loaded、Initialized、MouseEnter事件处理程序中将其更改为SizeWE,但在调整列大小后,它将变回默认值。尝试在MouseUp或DragCompleted事件处理程序中将其更改为SizeWE无效。在调整大小结束时释放鼠标按钮时,光标将更改为默认值。当在MouseEnter处理程序中完成SizeWE更改时,当鼠标退出并再次进入时,再次正常,但问题是在调整大小之后。
示例:
<Style x:Key="GridView.ColumnHeader.Gripper.Style" TargetType="{x:Type Thumb}" BasedOn="{StaticResource Theme.DataGrid.ColumnHeader.Gripper.Style}">
<Setter Property="Width" Value="20" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Cursor" Value="SizeWE" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Thumb}">
<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type GridViewColumnHeader}" >
<Setter Property="FontWeight" Value="{StaticResource Theme.DataGrid.ColumnHeader.FontWeight}"></Setter>
<Setter Property="BorderBrush" Value="Transparent"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
<Setter Property="Background" Value="{StaticResource Theme.DataGrid.ColumnHeader.Background}"></Setter>
<Setter Property="Foreground" Value="{StaticResource Theme.DataGrid.ColumnHeader.Foreground}"></Setter>
<Setter Property="HorizontalContentAlignment" Value="Left"></Setter>
<Setter Property="Padding" Value="{StaticResource Theme.DataGrid.Cell.Padding}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="1" />
</Grid.ColumnDefinitions>
<Border Grid.Column="0" x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}">
<ContentPresenter Margin="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<Thumb Grid.Column="1" x:Name="PART_HeaderGripper" HorizontalAlignment="Right"
Style="{DynamicResource GridView.ColumnHeader.Gripper.Style}"
Cursor="SizeWE"
MouseUp="PART_HeaderGripper_MouseUp"
MouseEnter="PART_HeaderGripper_MouseEnter"
Margin="-18,0, 0, 0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
代码隐藏:
private void PART_HeaderGripper_MouseUp(object sender, MouseButtonEventArgs e)
{
Thumb gripper = (Thumb)sender;
if (gripper != null)
{
gripper.Cursor = Cursors.SizeWE;
}
}
private void PART_HeaderGripper_MouseEnter(object sender, MouseEventArgs e)
{
Thumb gripper = (Thumb)sender;
if (gripper != null)
{
gripper.Cursor = Cursors.SizeWE;
}
}
2条答案
按热度按时间mrphzbgm1#
一个根本的解决方案是在光标进入Thumb时设置
Mouse.OverrideCursor
,并在光标离开时将其设置回来:处理程序:
slmsl1lt2#
执行此操作可强制将鼠标光标置于夹持器上,而不覆盖模板