UIElement.AllowDrop UIElement.AllowDrop UIElement.AllowDrop UIElement.AllowDrop Property

定义

获取或设置一个值,该值指示此元素能否用作拖放操作的目标。Gets or sets a value indicating whether this element can be used as the target of a drag-and-drop operation. 这是依赖项属性。This is a dependency property.

public:
 property bool AllowDrop { bool get(); void set(bool value); };
public bool AllowDrop { get; set; }
member this.AllowDrop : bool with get, set
Public Property AllowDrop As Boolean

属性值

如果此元素可用作拖放操作的目标,则为 true;否则为 falsetrue if this element can be used as the target of a drag-and-drop operation; otherwise, false. 默认值为 falseThe default value is false.

示例

以下AllowDrop标记示例true 使用上的属性TextBox设置属性,并设置聚合中的某些其他相关属性,使其能够在出现以下情况时成为多行文本数据对象的目标TextBox它将被拖入。The following markup example sets the AllowDrop property true using an attribute on a TextBox, as well as setting some other related properties that in aggregate enable that TextBox to be the target of a multiline text data object when it is dragged in. 有关完整示例, 请参阅加载已删除的文件示例For the complete sample, see Load a Dropped File Sample.

<TextBox
  Name="tbDisplayFileContents" 
  Grid.Row="1" 
  AcceptsReturn="True" AcceptsTab="True" 
  AllowDrop="True" 
  BorderThickness="1" BorderBrush="Black" 
  HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
  
  PreviewDragOver="ehDragOver" PreviewDrop="ehDrop"
/>

注解

默认情况下不启用拖放操作, 并且必须通过将设置AllowDrop为来true特意启用。Drag-and-drop operations are not enabled by default, and must be enabled deliberately by setting AllowDrop to true. 除了此基本设置外, 拖放行为完全是特定实现的, 并且不是由UIElement或任何其他基元素类定义的。Beyond this basic setting, drag-and-drop behavior is entirely implementation specific and is not defined by UIElement or any other base element class. 某些控件 (例如RichTextBox) 具有默认行为。Certain controls, for example, RichTextBox, do have a default behavior. 有关拖放的详细信息, 请参阅拖放概述For more information on drag and drop, see Drag and Drop Overview.

FrameworkElement在其实现中重写此依赖项属性的元数据。FrameworkElement overrides the metadata for this dependency property in its implementation. 具体而言FrameworkElement , 指定此属性以允许属性值继承Inherits true (在元数据中)。Specifically, FrameworkElement designates this property to allow property value inheritance (Inherits is true in metadata). 此上下文中的属性值继承表示, 如果有子元素没有任何其他值AllowDrop可通过本地值或样式进行分配, 则为已分配此值的最近父元素的值 (同样, 在样式中为默认值)值或本地值), 则父元素中的值将被属性系统分配给以前未分配的所有子元素。Property value inheritance in this context means that if there are child elements with no other value for AllowDrop assigned through local values or styles, the value of the nearest parent element with this value assigned (again, either in styles, by default values, or a local value), then the value from the parent element will be assigned to all previously unassigned child elements by the property system. 在实践中, 这意味着你可以指定是否允许在根元素处放置操作, 并且该值将传播到尚未专门将其分配为false的所有子元素。In practice this means that you can specify whether to allow drop operations at the root element, and that value will propagate to all child elements that have not specifically assigned it as false.

依赖项属性信息Dependency Property Information

标识符字段Identifier field AllowDropProperty
元数据属性设置为trueMetadata properties set to true NoneNone

适用于