首页 > 解决方案 > 如何将列表项拖放到图像视图 (WPF)?

问题描述

我想要的是将列表项从列表框中拖放到 WPF 中的 imageView 中。

所以我有一个列表框,其中包含一些列表项,例如:circle1、circle2 和带有图片的 imageView。现在我想在这张图片上拖放一个列表项。这个列表项在这张图片上显示为一个圆圈。

这可能吗?

我的带有列表框和图像的主 WPF:

<Window x:Class="MyProject.ControlCentre.UI.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:CLock.ControlCentre.UI"
    mc:Ignorable="d"
    Title="MyProject - ControlCentre" Height="391" Width="767" Icon="/Images/MyIcon.ico">

<Grid Background="#FF2B2B2B" Height="376">
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="0*"/>
    </Grid.RowDefinitions>

    <Menu x:Name="menuControlCentre" Margin="0,0,0,311" Background="#FF2B2B2B">
        <MenuItem x:Name="menuItemControlCentre" Header="_File" Foreground="White">
            <MenuItem x:Name="mItemLogInCC" Header="_LogIn" Foreground="Black"></MenuItem>
            <MenuItem x:Name="mItemLoadImageCC" Header="_Load Image" Foreground="Black" Click="mItemLoadImageCC_Click"></MenuItem>
            <MenuItem x:Name="meItemExitCC" Header="_Exit" Foreground="Black" Click="menueItemExitControlCentre_Click"></MenuItem>
        </MenuItem>
    </Menu>

    <ListBox x:Name="lbxCircles" Margin="10,58,562,23" Background="White" SelectionChanged="lbxDoors_SelectionChanged"/>
    <Label Content="Türen:" HorizontalAlignment="Left" Margin="10,32,0,0" VerticalAlignment="Top" Foreground="White" Height="26" Width="44"/>
    <Image x:Name="imgPlanOfRoom" HorizontalAlignment="Left" Height="228" Margin="247,58,0,0" VerticalAlignment="Top" Width="487"/>
    <Label Content="Plan of Room:" HorizontalAlignment="Left" Margin="247,35,0,0" VerticalAlignment="Top" Foreground="White"/>
</Grid>

我尝试用 AllowDrop 之类的东西来做,但没有用。我不知道如何实现列表项转换为圆形并拖放到 imageView 上的功能。

我希望有一个人可以帮助我。

标签: c#wpf

解决方案


推荐阅读