simples drag n drop -> egde cases müssen noch betrachtet werden

This commit is contained in:
2023-03-31 15:52:23 +02:00
parent a3ef1891f9
commit 5c0e2db7d1
2 changed files with 146 additions and 7 deletions

View File

@@ -83,7 +83,9 @@
ItemContainerStyle="{DynamicResource igoal_treeitemstyle}"
ItemTemplate="{DynamicResource igoal_treeitemtemplate}" Grid.RowSpan="1" ContextMenu="{StaticResource cmGoals}"
PreviewMouseDown="GoalTreeViewItem_PreviewMouseRightButtonDown"
ItemsSource="{Binding IndividualGoalTree, UpdateSourceTrigger=PropertyChanged}" >
ItemsSource="{Binding IndividualGoalTree, UpdateSourceTrigger=PropertyChanged}"
MouseDown="TreeView_MouseDown" MouseMove="TreeView_MouseMove"
AllowDrop="True" PreviewDragOver="TreeView_PreviewDragOver" PreviewDrop="TreeView_PreviewDrop" >
<TreeView.Resources>
<Style x:Key="igoal_treeitemstyle" TargetType="TreeViewItem">
<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}" />
@@ -102,7 +104,7 @@
<TextBox Margin="0,0,0,0" Cursor="Arrow" Background="Transparent" Height="21" Padding="0,3,0,0" VerticalAlignment="Center"
LostFocus="TextBox_LostFocus" KeyDown="TextBox_KeyDown" BorderThickness="0"
IsReadOnly="True" Text="{Binding Path=GoalEntryVM.DisplayName, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
FontWeight="{Binding Path=IsGoal, Converter={StaticResource ValueListEntryTypeToFontWeightConverter}}" ToolTipService.ShowDuration="100000">
FontWeight="{Binding Path=IsGoal, Converter={StaticResource ValueListEntryTypeToFontWeightConverter}}" ToolTipService.ShowDuration="100000" Focusable="False">
<TextBox.ToolTip>
<StackPanel Orientation="Vertical">
<Label FontWeight="Bold" Content="{Binding Path=GoalEntryVM.DisplayName, Mode=OneWay}"/>

View File

@@ -40,6 +40,9 @@ namespace BeWo.View.Detail
private MassnahmenTreeCopyType _CopyType;
private SupportConceptGoalTreeItem _CopyItem;
private Point _lastMouseDown;
private SupportConceptGoalTreeItem _draggedItem;
private SupportConceptGoalTreeItem _parent;
public MassnahmenTreeViewView(GenericValueListEntryListVM pViewModel)
{
@@ -86,6 +89,11 @@ namespace BeWo.View.Detail
{
_SelectedGoalTreeNode = null;
}
if (e.ChangedButton == MouseButton.Left)
{
_lastMouseDown = e.GetPosition(TreeView);
}
}
private void TextBox_LostFocus(object sender, RoutedEventArgs e)
@@ -161,14 +169,14 @@ namespace BeWo.View.Detail
else
{
if (selectedItem != null)
CopyTreeItem(selectedItem, _CopyItem);
CopyTreeItem(selectedItem, _CopyItem, false);
}
break;
}
}
private void CopyTreeItem(SupportConceptGoalTreeItem parent, SupportConceptGoalTreeItem source)
private void CopyTreeItem(SupportConceptGoalTreeItem parent, SupportConceptGoalTreeItem source, bool force_deep_copy)
{
if (source == null || parent == null)
throw new NotImplementedException("#43298467891364987");
@@ -176,11 +184,11 @@ namespace BeWo.View.Detail
var wm = source.GoalEntryVM;
var node = AddTreeItem(parent, wm.Type, wm.Description, wm.Abbreviation, wm.Notice);
if (_CopyType == MassnahmenTreeCopyType.Subtree)
if (_CopyType == MassnahmenTreeCopyType.Subtree || force_deep_copy)
{
foreach (var child in source.Items)
{
CopyTreeItem(node, child);
CopyTreeItem(node, child, force_deep_copy);
}
}
}
@@ -764,6 +772,135 @@ namespace BeWo.View.Detail
{
_Bearbeitungsmodus = false;
}
private void TreeView_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
{
_lastMouseDown = e.GetPosition(TreeView);
}
}
private void TreeView_MouseMove(object sender, MouseEventArgs e)
{
try
{
if (e.LeftButton == MouseButtonState.Pressed)
{
Point currentPosition = e.GetPosition(TreeView);
if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 10.0) ||
(Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 10.0))
{
_draggedItem = (SupportConceptGoalTreeItem)TreeView.SelectedItem;
if (_draggedItem != null)
{
DragDropEffects finalDropEffect = DragDrop.DoDragDrop(TreeView, _SelectedGoalTreeNode, DragDropEffects.Move);
//Checking target is not null and item is
//dragging(moving)
if ((finalDropEffect == DragDropEffects.Move) && (_parent != null) && _parent != _draggedItem)
{
var origin_parent = _draggedItem.ParentGoal as SupportConceptGoalTreeItem;
var parent = _parent;
var child = _draggedItem;
origin_parent.Items.Remove(child);
child.GoalEntryVM.ParentEntry = parent.GoalEntryDC ?? parent.GoalEntryVM.CommitToDataContract();
parent.Items.Add(_draggedItem);
parent.IsExpanded = true;
TreeView.RefreshUI();
}
}
}
}
}
catch (Exception)
{
}
}
private SupportConceptGoalTreeItem GetNearestContainer(UIElement element)
{
// Walk up the element tree to the nearest tree view item.
TreeViewItem container = element as TreeViewItem;
while ((container == null) && (element != null))
{
element = VisualTreeHelper.GetParent(element) as UIElement;
container = element as TreeViewItem;
}
return container.DataContext as SupportConceptGoalTreeItem;
//return container;
}
private bool CheckDropTarget(SupportConceptGoalTreeItem _sourceItem, SupportConceptGoalTreeItem _targetItem)
{
if (_sourceItem == null || _targetItem == null)
return false;
//Check whether the target item is meeting your condition
var source = _sourceItem as SupportConceptGoalTreeItem;
var target = _targetItem as SupportConceptGoalTreeItem;
bool _isEqual = false;
// Unterschiedlicher Parent
if (source.GoalEntryVM.ParentEntry.ValueListEntryOid.Value != target.GoalEntryDC.ValueListEntryOid.Value)
{
// Nicht eigener
if (!IstGleichesZiel(source.GoalEntryVM, target.GoalEntryVM))
{
_isEqual = true;
}
}
return _isEqual;
}
private void TreeView_PreviewDragOver(object sender, DragEventArgs e)
{
try
{
Point currentPosition = e.GetPosition(TreeView);
if ((Math.Abs(currentPosition.X - _lastMouseDown.X) > 0.0) ||
(Math.Abs(currentPosition.Y - _lastMouseDown.Y) > 0.0))
{
// Verify that this is a valid drop and then store the drop target
var item = GetNearestContainer(e.OriginalSource as UIElement);
if (CheckDropTarget(_draggedItem, item))
{
e.Effects = DragDropEffects.Move;
}
else
{
e.Effects = DragDropEffects.None;
}
}
e.Handled = true;
}
catch (Exception)
{
}
}
private void TreeView_PreviewDrop(object sender, DragEventArgs e)
{
try
{
e.Effects = DragDropEffects.None;
e.Handled = true;
// Verify that this is a valid drop and then store the drop target
var target = GetNearestContainer(e.OriginalSource as UIElement);
if (target != null && _draggedItem != null)
{
_parent = target;
e.Effects = DragDropEffects.Move;
}
}
catch (Exception)
{
}
}
}
public class ValueListEntryTypeToFontWeightConverter : IValueConverter