UIElement.AllowDrop 屬性

定義

取得或設定此元素是否可以當做拖放操作目標的值。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

屬性值

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.

範例

下列標記範例會使用中 AllowDroptrue 屬性來設定屬性 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 trueDrag-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. 在實務上,這表示您可以指定是否要允許根項目的 drop 作業,該值將會傳播至尚未明確指派為的所有子項目 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 NoneNone

適用於