DockPattern.SetDockPosition(DockPosition) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將 AutomationElement 停駐在停駐容器內要求的 DockPosition。
public:
void SetDockPosition(System::Windows::Automation::DockPosition dockPosition);
public void SetDockPosition (System.Windows.Automation.DockPosition dockPosition);
member this.SetDockPosition : System.Windows.Automation.DockPosition -> unit
Public Sub SetDockPosition (dockPosition As DockPosition)
參數
- dockPosition
- DockPosition
相對於停駐容器界限及容器內其他項目的停駐位置。
例外狀況
當控制項無法執行要求的停駐樣式時。
範例
在下列範例中, AutomationElement 表示支援 DockPattern 控制項模式的控制項已修改。 dockPosition
///--------------------------------------------------------------------
/// <summary>
/// Obtains a DockPattern control pattern from an
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A DockPattern object.
/// </returns>
///--------------------------------------------------------------------
private DockPattern GetDockPattern(
AutomationElement targetControl)
{
DockPattern dockPattern = null;
try
{
dockPattern =
targetControl.GetCurrentPattern(
DockPattern.Pattern)
as DockPattern;
}
// Object doesn't support the DockPattern control pattern
catch (InvalidOperationException)
{
return null;
}
return dockPattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a DockPattern control pattern from an
''' automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A DockPattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetDockPattern( _
ByVal targetControl As AutomationElement) As DockPattern
Dim dockPattern As DockPattern = Nothing
Try
dockPattern = DirectCast( _
targetControl.GetCurrentPattern(dockPattern.Pattern), _
DockPattern)
Catch exc As InvalidOperationException
' Object doesn't support the DockPattern control pattern
Return Nothing
End Try
Return dockPattern
End Function 'GetDockPattern
///--------------------------------------------------------------------
/// <summary>
/// Sets the dock position of a target.
/// </summary>
/// <param name="dockControl">
/// The automation element of interest.
/// </param>
/// <param name="dockPosition">
/// The requested DockPosition.
/// </param>
///--------------------------------------------------------------------
private void SetDockPositionOfControl(
AutomationElement dockControl, DockPosition dockPosition)
{
if (dockControl == null)
{
throw new ArgumentNullException(
"AutomationElement parameter must not be null.");
}
try
{
DockPattern dockPattern = GetDockPattern(dockControl);
if (dockPattern == null)
{
return;
}
dockPattern.SetDockPosition(dockPosition);
}
catch (InvalidOperationException)
{
// When a control is not able to dock.
// TO DO: error handling
}
}
'''--------------------------------------------------------------------
''' <summary>
''' Sets the dock position of a target.
''' </summary>
''' <param name="dockControl">
''' The automation element of interest.
''' </param>
''' <param name="dockPosition">
''' The requested DockPosition.
''' </param>
'''--------------------------------------------------------------------
Private Sub SetDockPositionOfControl( _
ByVal dockControl As AutomationElement, _
ByVal dockPosition As DockPosition)
If dockControl Is Nothing Then
Throw New ArgumentNullException( _
"AutomationElement parameter must not be null.")
End If
Try
Dim dockPattern As DockPattern = GetDockPattern(dockControl)
If dockPattern Is Nothing Then
Return
End If
dockPattern.SetDockPosition(dockPosition)
Catch exc As InvalidOperationException
' When a control is not able to dock.
' TO DO: error handling
End Try
End Sub
備註
停駐容器是一種控制項,可允許水準和垂直排列子項目,相對於停駐容器的界限,以及容器內的其他元素。