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"
/>

備註

拖放作業不會預設啟用,且必須藉由設定刻意啟用AllowDroptrueDrag-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指定此屬性,以允許屬性值繼承 (Inheritstrue中繼資料中)。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. 實際上這表示您可以指定是否要在根項目允許卸除作業,並將它做為值將會傳播至所有子項目具有不是明確地指派falseIn 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 None

適用於