WPF从列表框拖动元素
在我的WPF应用程序中,我有一个列表框,其中的DataTemplate定义如下: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
<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范围之外