TextRange.IsEmpty プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
現在の選択範囲が空かどうかを示す値を取得します。
public:
property bool IsEmpty { bool get(); };
public bool IsEmpty { get; }
member this.IsEmpty : bool
Public ReadOnly Property IsEmpty As Boolean
プロパティ値
現在の選択範囲が空の場合は true
。それ以外の場合は false
。
例
次の例では、 プロパティの使用方法を IsEmpty 示します。
// This method accepts an input stream and a corresponding data format. The method
// will attempt to load the input stream into a TextRange selection, apply Bold formatting
// to the selection, save the reformatted selection to an alternat stream, and return
// the reformatted stream.
Stream BoldFormatStream(Stream inputStream, string dataFormat)
{
// A text container to read the stream into.
FlowDocument workDoc = new FlowDocument();
TextRange selection = new TextRange(workDoc.ContentStart, workDoc.ContentEnd);
Stream outputStream = new MemoryStream();
try
{
// Check for a valid data format, and then attempt to load the input stream
// into the current selection. Note that CanLoad ONLY checks whether dataFormat
// is a currently supported data format for loading a TextRange. It does not
// verify that the stream actually contains the specified format. An exception
// may be raised when there is a mismatch between the specified data format and
// the data in the stream.
if (selection.CanLoad(dataFormat))
selection.Load(inputStream, dataFormat);
}
catch (Exception e) { return outputStream; /* Load failure; return a null stream. */ }
// Apply Bold formatting to the selection, if it is not empty.
if (!selection.IsEmpty)
selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
// Save the formatted selection to a stream, and return the stream.
if (selection.CanSave(dataFormat))
selection.Save(outputStream, dataFormat);
return outputStream;
}
' This method accepts an input stream and a corresponding data format. The method
' will attempt to load the input stream into a TextRange selection, apply Bold formatting
' to the selection, save the reformatted selection to an alternat stream, and return
' the reformatted stream.
Private Function BoldFormatStream(ByVal inputStream As Stream, ByVal dataFormat As String) As Stream
' A text container to read the stream into.
Dim workDoc As New FlowDocument()
Dim selection As New TextRange(workDoc.ContentStart, workDoc.ContentEnd)
Dim outputStream As Stream = New MemoryStream()
Try
' Check for a valid data format, and then attempt to load the input stream
' into the current selection. Note that CanLoad ONLY checks whether dataFormat
' is a currently supported data format for loading a TextRange. It does not
' verify that the stream actually contains the specified format. An exception
' may be raised when there is a mismatch between the specified data format and
' the data in the stream.
If selection.CanLoad(dataFormat) Then
selection.Load(inputStream, dataFormat)
End If
Catch e As Exception ' Load failure return a null stream.
Return outputStream
End Try
' Apply Bold formatting to the selection, if it is not empty.
If Not selection.IsEmpty Then
selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold)
End If
' Save the formatted selection to a stream, and return the stream.
If selection.CanSave(dataFormat) Then
selection.Save(outputStream, dataFormat)
End If
Return outputStream
End Function
注釈
TextRangeと End の位置が等しい場合、 Start は空と見なされます。
適用対象
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET