我在复杂TextBox
UserControl
控件
我想从Windows资源管理器中删除文件。 这是XAML代码:
<TextBox x:Name="txtMessage"
AcceptsReturn="True"
AcceptsTab="True"
AllowDrop="True"
PreviewDragOver="TxtMessage_OnDragEnter"
PreviewDragEnter="TxtMessage_OnDragEnter"
PreviewDrop="TxtMessage_OnDrop"
IsEnabled="{Binding IsMessageFieldEnabled}"
Text="{Binding Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
FontSize="14">
<TextBox.InputBindings>
<KeyBinding Key="Enter"
Command="{Binding CommandSendMessage}">
</KeyBinding>
</TextBox.InputBindings>
</TextBox>
以下是代码:
private void TxtMessage_OnDrop(object sender, DragEventArgs e)
{
IDragAndDrop dd = DataContext as IDragAndDrop;
if (dd == null)
{
return;
}
dd.TryDrop(e.Data);
e.Handled = true;
}
private void TxtMessage_OnDragEnter(object sender, DragEventArgs e)
{
IDragAndDrop dd = DataContext as IDragAndDrop;
if (dd == null)
{
e.Effects = DragDropEffects.None;
return;
}
e.Effects = dd.CheckForAllowedDragDrop(e.Data);
e.Handled = true;
}
问题是我的代码根本没有被调用。为什么会这样?什么会阻止拖累和放弃某些控件的工作?