Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Wpf拖放项控件_C#_Wpf_Drag And Drop - Fatal编程技术网

C# Wpf拖放项控件

C# Wpf拖放项控件,c#,wpf,drag-and-drop,C#,Wpf,Drag And Drop,我需要拖放itemcontrol项中的所有elemet,只有在药物的第一个标签上 using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using

我需要拖放itemcontrol项中的所有elemet,只有在药物的第一个标签上

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GongSolutions.Wpf;
using System.Xml.Serialization;
using System.IO;
using System.Diagnostics;
namespace DragAndDropBehavior
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
/// 
public class DataStruct
{
    public int number { get; set; }
    public string Name { get; set; }
}
[Serializable]
public class TestSer
{
    public ObservableCollection<DataStruct> Items { get; set; }
    public string Names { get; set; }
    public TestSer()
    {
        Items = new ObservableCollection<DataStruct>();
        Items.Add(new DataStruct {number=1,Name="First"});
        Items.Add(new DataStruct {number=2,Name="Two"});
        Items.Add(new DataStruct {number=3,Name="Three"});
    }
}


public partial class MainWindow : Window
{
    TestSer Some;
    public MainWindow()
    {
        this.DataContext = new TestSer();
        InitializeComponent();
    }
    public object tempSendre { get; set; }
    private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
    }

    private void Label_Drop(object sender, DragEventArgs e)
    {
        (tempSendre as Label).Content = ((Label)sender).Content;
        (sender as Label).Content = e.Data.GetData(DataFormats.Text);
    }

    private void Label_MouseDown(object sender, MouseButtonEventArgs e)
    {
        tempSendre = sender;
        Label lbl = (Label)sender;
        DragDrop.DoDragDrop(lbl, lbl.Content, DragDropEffects.Copy);
    }
}
}
Xaml代码

<Window x:Class="DragAndDropBehavior.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
    Title="MainWindow" Height="350" Width="525" Closing="Window_Closing">
<StackPanel>
    <ItemsControl ItemsSource="{Binding Items}" x:Name="TestControl">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <UniformGrid Rows="2" Columns="4" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Border BorderBrush="#FF000000" BorderThickness="1,1,1,1" CornerRadius="8,8,8,8" Margin="5">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                            <RowDefinition></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition></ColumnDefinition>
                            <ColumnDefinition></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Label Grid.Row="0" Content="{Binding Name}" Grid.ColumnSpan="2" Drop="Label_Drop" MouseDown="Label_MouseDown" AllowDrop="True"></Label>
                        <Label Grid.Row="1" Content="{Binding number}"></Label>
                        <Button Grid.Row="2" Content="{Binding Name}"></Button>
                    </Grid>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</StackPanel>
起初我用的是NuGet的Gong,但它不正确。
**

那么你的问题又是什么呢?我怎样才能将所有物品从第一件物品复制到第二件物品,只在第一件物品和第二件物品之间添加一个第一标签。Bacuse对象发送器仅包含标签对象。