Skip to content

Commit a873b04

Browse files
committed
feat: 添加数据网格指针移动事件处理,以支持悬停项的识别
1 parent 93061d4 commit a873b04

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/Views/Histories.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
Loaded="OnCommitListLoaded"
4545
LayoutUpdated="OnCommitListLayoutUpdated"
4646
SelectionChanged="OnCommitListSelectionChanged"
47+
PointerMoved="OnDataGridPointerMoved"
4748
ContextRequested="OnCommitListContextRequested"
4849
DoubleTapped="OnCommitListDoubleTapped"
4950
KeyDown="OnCommitListKeyDown">

src/Views/Histories.axaml.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,28 @@ private void OnCommitListSelectionChanged(object _, SelectionChangedEventArgs e)
235235
e.Handled = true;
236236
}
237237

238+
private object _hoveredItem;
239+
240+
private void OnDataGridPointerMoved(object sender, PointerEventArgs e)
241+
{
242+
var dataGrid = sender as DataGrid;
243+
var point = e.GetPosition(dataGrid);
244+
var visual = dataGrid.InputHitTest(point) as Control;
245+
246+
// 向上找 DataGridRow
247+
while (visual != null && !(visual is Avalonia.Controls.DataGridRow))
248+
visual = visual.Parent as Control;
249+
250+
if (visual is Avalonia.Controls.DataGridRow row)
251+
{
252+
var item = row.DataContext;
253+
if (!Equals(_hoveredItem, item))
254+
{
255+
_hoveredItem = item;
256+
}
257+
}
258+
}
259+
238260
private void OnCommitListContextRequested(object sender, ContextRequestedEventArgs e)
239261
{
240262
if (sender is DataGrid { SelectedItems: { } selected } dataGrid &&

0 commit comments

Comments
 (0)