V1.0
This commit is contained in:
@@ -15,6 +15,11 @@ namespace DrillTools
|
||||
/// </summary>
|
||||
public bool IsConfirmed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 标记是否正在处理选中项同步,防止递归调用
|
||||
/// </summary>
|
||||
private bool _isSynchronizingSelection = false;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
@@ -97,6 +102,104 @@ namespace DrillTools
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 原始刀序列表选中项变化事件处理
|
||||
/// </summary>
|
||||
private void OriginalToolsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (_isSynchronizingSelection)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
_isSynchronizingSelection = true;
|
||||
|
||||
if (OriginalToolsListView.SelectedItem is ToolOrderItem selectedOriginalItem)
|
||||
{
|
||||
// 在重排后列表中查找对应的刀具
|
||||
var matchingItem = FindMatchingToolItem(ReorderedToolsListView, selectedOriginalItem);
|
||||
if (matchingItem != null)
|
||||
{
|
||||
ReorderedToolsListView.SelectedItem = matchingItem;
|
||||
// 确保选中的项可见
|
||||
ReorderedToolsListView.ScrollIntoView(matchingItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果原始列表没有选中项,清空重排后列表的选中项
|
||||
ReorderedToolsListView.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSynchronizingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重排后刀序列表选中项变化事件处理
|
||||
/// </summary>
|
||||
private void ReorderedToolsListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (_isSynchronizingSelection)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
_isSynchronizingSelection = true;
|
||||
|
||||
if (ReorderedToolsListView.SelectedItem is ToolOrderItem selectedReorderedItem)
|
||||
{
|
||||
// 在原始列表中查找对应的刀具
|
||||
var matchingItem = FindMatchingToolItem(OriginalToolsListView, selectedReorderedItem);
|
||||
if (matchingItem != null)
|
||||
{
|
||||
OriginalToolsListView.SelectedItem = matchingItem;
|
||||
// 确保选中的项可见
|
||||
OriginalToolsListView.ScrollIntoView(matchingItem);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果重排后列表没有选中项,清空原始列表的选中项
|
||||
OriginalToolsListView.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_isSynchronizingSelection = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在ListView中查找匹配的刀具项
|
||||
/// </summary>
|
||||
/// <param name="listView">要搜索的ListView</param>
|
||||
/// <param name="targetItem">目标刀具项</param>
|
||||
/// <returns>匹配的刀具项,如果未找到则返回null</returns>
|
||||
private ToolOrderItem FindMatchingToolItem(System.Windows.Controls.ListView listView, ToolOrderItem targetItem)
|
||||
{
|
||||
if (listView?.ItemsSource == null || targetItem == null)
|
||||
return null;
|
||||
|
||||
foreach (var item in listView.Items)
|
||||
{
|
||||
if (item is ToolOrderItem toolItem)
|
||||
{
|
||||
// 使用与ViewModel中相同的匹配逻辑:基于孔径和刀具类型
|
||||
// 注意:这里使用ToolTypeDisplay进行比较,因为ToolOrderItem中没有ToolType属性
|
||||
if (Math.Abs(toolItem.Diameter - targetItem.Diameter) < 0.001 &&
|
||||
toolItem.ToolTypeDisplay == targetItem.ToolTypeDisplay)
|
||||
{
|
||||
return toolItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取ListView中的ScrollViewer控件
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user