首页 > 解决方案 > 处理重叠的拖动形状

问题描述

我正在做一个用户可以拖动这个形状的程序。形状是: 中频形状 动作形状

它可以相互连接以制作新的块。但问题是,当我将两个 [Blue] Shape 拖入 [If] Shape 时,我无法再拖动 [Blue],导致 [If] Shape 折叠并导致 [Blue] Shape 无法交互. 在此处输入图像描述

这是我的代码:
形状的定义

<UserControl x:Class="SampleCode.ActionShape"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:SampleCode"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             mc:Ignorable="d" >
    <UserControl.Resources>
        <local:ColorToBrushConverter x:Key="colorToBrushConverter"/>
        <local:ThicknessConverter x:Key="thicknessConverter"/>
    </UserControl.Resources>
    <Grid>
        <Path Data="{Binding SvgData}"
              Fill="{Binding Color, Converter={StaticResource colorToBrushConverter}}"
              Cursor="Hand">
        </Path>
        <TextBlock Foreground="{Binding TextColor, Converter={StaticResource colorToBrushConverter}}" FontSize="{Binding FontSize}" Margin="{Binding MarginText}" Text="{Binding Text}"></TextBlock>
    </Grid>
</UserControl>

主窗口.xaml

<Window x:Class="SampleCode.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SampleCode"
    Title="" 
    Width="1400"
    Height="800"
    Loaded="Window_Loaded">
    <Window.Resources>
        <local:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
        <DataTemplate DataType="{x:Type local:BaseShapeMVVm}">
            <local:ActionShape AllowDrop="True" MouseDown="Rectangle_MouseDown" MouseMove="Rectangle_MouseMove" MouseUp="Rectangle_MouseUp"></local:ActionShape>
        </DataTemplate>
    </Window.Resources>
    <Window.DataContext>
        <local:ViewModel />
    </Window.DataContext>
    <Grid>
        <TreeView  Name="ListBox" ItemsSource="{Binding Rectangles}">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Canvas />
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemContainerStyle>
                <Style TargetType="TreeViewItem">
                    <Setter
                        Property="Canvas.Left" Value="{Binding X}"/>
                    <Setter
                        Property="Canvas.Top" Value="{Binding Y}"/>
                </Style>
            </ItemsControl.ItemContainerStyle>
        </TreeView>
    </Grid>
</Window>

你能给我一些关于这个问题的建议吗?我很兴奋

标签: wpfdrag-and-drop

解决方案


推荐阅读