Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
WPF从列表框拖动元素_Wpf_Drag And Drop - Fatal编程技术网

WPF从列表框拖动元素

WPF从列表框拖动元素,wpf,drag-and-drop,Wpf,Drag And Drop,在我的WPF应用程序中,我有一个列表框,其中的DataTemplate定义如下: <DataTemplate x:Key="ListBoxTemplate"> <ui:TaskMonthPreview/> </DataTemplate> <UserControl x:Class="Lista.TaskMonthPreview" xmlns="http://schemas.microsoft.com/winfx/200

在我的WPF应用程序中,我有一个列表框,其中的DataTemplate定义如下:

 <DataTemplate x:Key="ListBoxTemplate">
            <ui:TaskMonthPreview/>
 </DataTemplate>
<UserControl x:Class="Lista.TaskMonthPreview"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="30" Width="100">

    <UserControl.Resources>
        <ResourceDictionary>
            <ControlTemplate x:Key="TaskView" TargetType="Thumb">

                <Rectangle
                Name="rectangle1" 
                Stroke="Chocolate" 
                HorizontalAlignment="Left" 
                Width="{TemplateBinding Width}" 
                Height="{TemplateBinding Height}" 
                Fill="LightSkyBlue"/>

            </ControlTemplate>
        </ResourceDictionary>
    </UserControl.Resources>



        <Thumb Name="myThumb"  Background="Blue" 
          Width="100" Height="20" DragDelta="onDragDelta" 
          DragStarted="onDragStarted" DragCompleted="onDragCompleted" HorizontalAlignment="Left"
          Template="{StaticResource TaskView}"/>



</UserControl>
TaskMonthPreview是我的自定义控件,定义如下:

 <DataTemplate x:Key="ListBoxTemplate">
            <ui:TaskMonthPreview/>
 </DataTemplate>
<UserControl x:Class="Lista.TaskMonthPreview"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="30" Width="100">

    <UserControl.Resources>
        <ResourceDictionary>
            <ControlTemplate x:Key="TaskView" TargetType="Thumb">

                <Rectangle
                Name="rectangle1" 
                Stroke="Chocolate" 
                HorizontalAlignment="Left" 
                Width="{TemplateBinding Width}" 
                Height="{TemplateBinding Height}" 
                Fill="LightSkyBlue"/>

            </ControlTemplate>
        </ResourceDictionary>
    </UserControl.Resources>



        <Thumb Name="myThumb"  Background="Blue" 
          Width="100" Height="20" DragDelta="onDragDelta" 
          DragStarted="onDragStarted" DragCompleted="onDragCompleted" HorizontalAlignment="Left"
          Template="{StaticResource TaskView}"/>



</UserControl>
我在TaskMonthPreview中的拇指是可拖动的,但不幸的是,它不能拖动到TaskMonthPreview区域之外。是否可以将我的拇指拖动到TaskMonthPreview范围之外,甚至listbox范围之外