ValuePattern.ValuePatternInformation.IsReadOnly 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
UI 자동화 요소의 값이 읽기 전용인지 여부를 지정하는 값을 가져옵니다.
public:
property bool IsReadOnly { bool get(); };
public bool IsReadOnly { get; }
member this.IsReadOnly : bool
Public ReadOnly Property IsReadOnly As Boolean
속성 값
값이 읽기 전용이면 true
이고, 값을 수정할 수 있으면 false
입니다.
예제
다음 예제에서는 AutomationElement 지는 ValuePattern 컨트롤 패턴에 해당 ValueProperty 사용자 지정 값으로 설정 합니다.
///--------------------------------------------------------------------
/// <summary>
/// Inserts a string into a text control that supports ValuePattern.
/// </summary>
/// <param name="targetControl">A text control.</param>
/// <param name="value">The string to be inserted.</param>
///--------------------------------------------------------------------
private void InsertText(AutomationElement targetControl,
string value)
{
// Validate arguments / initial setup
if (value == null)
throw new ArgumentNullException(
"String parameter must not be null.");
if (targetControl == null)
throw new ArgumentNullException(
"AutomationElement parameter must not be null");
// A series of basic checks prior to attempting an insertion.
//
// Check #1: Is control enabled?
// An alternative to testing for static or read-only controls
// is to filter using
// PropertyCondition(AutomationElement.IsEnabledProperty, true)
// and exclude all read-only text controls from the collection.
if (!targetControl.Current.IsEnabled)
{
throw new InvalidOperationException(
"The control is not enabled.\n\n");
}
// Check #2: Are there styles that prohibit us
// from sending text to this control?
if (!targetControl.Current.IsKeyboardFocusable)
{
throw new InvalidOperationException(
"The control is not focusable.\n\n");
}
// Once you have an instance of an AutomationElement,
// check if it supports the ValuePattern pattern.
object valuePattern = null;
if (!targetControl.TryGetCurrentPattern(
ValuePattern.Pattern, out valuePattern))
{
// Elements that support TextPattern
// do not support ValuePattern and TextPattern
// does not support setting the text of
// multi-line edit or document controls.
// For this reason, text input must be simulated.
}
// Control supports the ValuePattern pattern so we can
// use the SetValue method to insert content.
else
{
if (((ValuePattern)valuePattern).Current.IsReadOnly)
{
throw new InvalidOperationException(
"The control is read-only.");
}
else
{
((ValuePattern)valuePattern).SetValue(value);
}
}
}
'''--------------------------------------------------------------------
''' <summary>
''' Inserts a string into a text control that supports ValuePattern.
''' </summary>
''' <param name="targetControl">A text control.</param>
''' <param name="value">The string to be inserted.</param>
'''--------------------------------------------------------------------
Private Sub InsertText(ByVal targetControl As AutomationElement, _
ByVal value As String)
' Validate arguments / initial setup
If value Is Nothing Then
Throw New ArgumentNullException( _
"String parameter must not be null.")
End If
If targetControl Is Nothing Then
Throw New ArgumentNullException( _
"AutomationElement parameter must not be null")
End If
' A series of basic checks prior to attempting an insertion.
'
' Check #1: Is control enabled?
' An alternative to testing for static or read-only controls
' is to filter using
' PropertyCondition(AutomationElement.IsEnabledProperty, true)
' and exclude all read-only text controls from the collection.
If Not targetControl.Current.IsEnabled Then
Throw New InvalidOperationException( _
"The control is not enabled." + vbLf + vbLf)
End If
' Check #2: Are there styles that prohibit us
' from sending text to this control?
If Not targetControl.Current.IsKeyboardFocusable Then
Throw New InvalidOperationException( _
"The control is not focusable." + vbLf + vbLf)
End If
' Once you have an instance of an AutomationElement,
' check if it supports the ValuePattern pattern.
Dim valuePattern As Object = Nothing
If Not targetControl.TryGetCurrentPattern( _
valuePattern.Pattern, valuePattern) Then
' Elements that support TextPattern
' do not support ValuePattern and TextPattern
' does not support setting the text of
' multi-line edit or document controls.
' For this reason, text input must be simulated.
' Control supports the ValuePattern pattern so we can
' use the SetValue method to insert content.
Else
If CType(valuePattern, ValuePattern).Current.IsReadOnly Then
Throw New InvalidOperationException("The control is read-only.")
Else
CType(valuePattern, ValuePattern).SetValue(value)
End If
End If
End Sub
설명
컨트롤 있어야 해당 IsEnabledProperty 로 설정 true
및 해당 IsReadOnlyProperty 로 설정 false
클라이언트를 호출 하기 전에 SetValue입니다.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET