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

屬性值

如果這個項目可以當做拖放操作目標的值,則為true ;否則為 falsetrue if this element can be used as the target of a drag-and-drop operation; otherwise, false. 預設值為 falseThe default value is false.

範例

下列標記範例會使用 TextBox上的屬性來設定 AllowDrop 屬性 true,以及設定一些其他相關的屬性,這些屬性在匯總中可讓該 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. 實際上,這表示您可以指定是否允許在根項目上進行 drop 作業,而該值將會傳播到尚未明確指派給 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
設定為 true 的中繼資料屬性Metadata properties set to true NoneNone

適用於