Span 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 Span 類別的新實例。
多載
Span() |
初始化 Span 類別的新空白實例。 |
Span(Inline) | |
Span(Inline, TextPointer) |
初始化 Span 類別的新實例,以指定的 Inline 對象作為新 Span的初始內容,以及指定新 Inline 專案插入位置的 TextPointer。 |
Span(TextPointer, TextPointer) |
初始化 Span 類別的新實例,並採用兩個 TextPointer 物件,指出新 Span 將包含之內容的開始和結尾。 |
Span()
Span(Inline)
public:
Span(System::Windows::Documents::Inline ^ childInline);
public Span (System.Windows.Documents.Inline childInline);
new System.Windows.Documents.Span : System.Windows.Documents.Inline -> System.Windows.Documents.Span
Public Sub New (childInline As Inline)
參數
範例
下列範例示範如何使用這個建構函式來建立包含 Run的新Span。
// A child Inline element for the new Span element.
Run runx = new Run("The Run element derives from Inline, and is therefore" +
"an acceptable child element for this new Span.");
// After this line executes, the new element "spanx"
// contains the specified Inline element, "runx".
Span spanx = new Span(runx);
' A child Inline element for the new Span element.
Dim runx1 As New Run("The Run element derives from Inline, and is therefore" & "an acceptable child element for this new Span.")
' After this line executes, the new element "spanx"
' contains the specified Inline element, "runx".
Dim spanx1 As New Span(runx1)
適用於
Span(Inline, TextPointer)
初始化 Span 類別的新實例,以指定的 Inline 對象作為新 Span的初始內容,以及指定新 Inline 專案插入位置的 TextPointer。
public:
Span(System::Windows::Documents::Inline ^ childInline, System::Windows::Documents::TextPointer ^ insertionPosition);
public Span (System.Windows.Documents.Inline childInline, System.Windows.Documents.TextPointer insertionPosition);
new System.Windows.Documents.Span : System.Windows.Documents.Inline * System.Windows.Documents.TextPointer -> System.Windows.Documents.Span
Public Sub New (childInline As Inline, insertionPosition As TextPointer)
參數
- insertionPosition
- TextPointer
TextPointer,指定要在建立項目之後插入 Span 專案的位置,或為無自動插入的 null。
範例
下列範例示範如何使用這個建構函式來建立新的 Span,其中包含在 Paragraph開頭插入的 Run。
// A child Inline element for the new Span element.
Run runx = new Run("The Run element derives from Inline, and is therefore" +
"an acceptable child element for this new Span.");
// An empty paragraph will serve as the container for the new Span element.
Paragraph parx = new Paragraph();
// After this line executes, the new element "spanx"
// contains the specified Inline element, "runx". Also, "spanx" is
// inserted at the point indicated by the insertionPosition parameter,
// which in this case indicates the content start position in the Paragraph
// element "parx".
Span spanx = new Span(runx, parx.ContentStart);
' A child Inline element for the new Span element.
Dim runx2 As New Run("The Run element derives from Inline, and is therefore" & "an acceptable child element for this new Span.")
' An empty paragraph will serve as the container for the new Span element.
Dim parx2 As New Paragraph()
' After this line executes, the new element "spanx"
' contains the specified Inline element, "runx". Also, "spanx" is
' inserted at the point indicated by the insertionPosition parameter,
' which in this case indicates the content start position in the Paragraph
' element "parx".
Dim spanx2 As New Span(runx2, parx2.ContentStart)
適用於
Span(TextPointer, TextPointer)
初始化 Span 類別的新實例,並採用兩個 TextPointer 物件,指出新 Span 將包含之內容的開始和結尾。
public:
Span(System::Windows::Documents::TextPointer ^ start, System::Windows::Documents::TextPointer ^ end);
public Span (System.Windows.Documents.TextPointer start, System.Windows.Documents.TextPointer end);
new System.Windows.Documents.Span : System.Windows.Documents.TextPointer * System.Windows.Documents.TextPointer -> System.Windows.Documents.Span
Public Sub New (start As TextPointer, end As TextPointer)
參數
- start
- TextPointer
TextPointer,指出新 Span 將包含之內容的開始。
- end
- TextPointer
TextPointer,指出新 Span 將包含之內容選取範圍的結尾。
例外狀況
當 start
或 end
為 null 時引發。
當 start
和 end
無法解析為適合 Span 元素機箱的內容範圍時引發;例如,如果 start
和 end
表示不同段落中的位置。
範例
下列範例示範如何使用這個建構函式來建立套用至內容範圍的新 Span。 內容的範圍取決於建構函式所指定的開始和結束 TextPointer 物件。
// Create a paragraph and three text runs to serve as example content.
Paragraph parx = new Paragraph();
Run run1 = new Run("Text run 1.");
Run run2 = new Run("Text run 2.");
Run run3 = new Run("Text run 3.");
// Add the three text runs to the paragraph, separated by linebreaks.
parx.Inlines.Add(run1);
parx.Inlines.Add(new LineBreak());
parx.Inlines.Add(run2);
parx.Inlines.Add(new LineBreak());
parx.Inlines.Add(run3);
// After this line executes, the selection of content
// indicated by the "start" and "end" parameters will be
// enclosed by the new Span. In this case, the new Span
// will enclose the entire contents of the Paragraph "parx",
// which happens to contain three text runs and two linebreaks.
Span spanx = new Span(parx.ContentStart, parx.ContentEnd);
// Now, properties set on "spanx" will override default properties
// on elements contained by "spanx". For example, setting
// these arbitrary display properties on "spanx" will affect
// the child text runs enclosed by "spanx".
spanx.Foreground = Brushes.Blue;
spanx.Background = Brushes.GhostWhite;
spanx.FontFamily = new FontFamily("Century Gothic");
// Non-default property values override any settings on the
// enclosing Span element.
run2.Foreground = Brushes.Red;
run2.Background = Brushes.AntiqueWhite;
run2.FontFamily = new FontFamily("Lucida Handwriting");
' Create a paragraph and three text runs to serve as example content.
Dim parx3 As New Paragraph()
Dim run1 As New Run("Text run 1.")
Dim run2 As New Run("Text run 2.")
Dim run3 As New Run("Text run 3.")
' Add the three text runs to the paragraph, separated by linebreaks.
parx3.Inlines.Add(run1)
parx3.Inlines.Add(New LineBreak())
parx3.Inlines.Add(run2)
parx3.Inlines.Add(New LineBreak())
parx3.Inlines.Add(run3)
' After this line executes, the selection of content
' indicated by the "start" and "end" parameters will be
' enclosed by the new Span. In this case, the new Span
' will enclose the entire contents of the Paragraph "parx",
' which happens to contain three text runs and two linebreaks.
Dim spanx As New Span(parx3.ContentStart, parx3.ContentEnd)
' Now, properties set on "spanx" will override default properties
' on elements contained by "spanx". For example, setting
' these arbitrary display properties on "spanx" will affect
' the child text runs enclosed by "spanx".
spanx.Foreground = Brushes.Blue
spanx.Background = Brushes.GhostWhite
spanx.FontFamily = New FontFamily("Century Gothic")
' Non-default property values override any settings on the
' enclosing Span element.
run2.Foreground = Brushes.Red
run2.Background = Brushes.AntiqueWhite
run2.FontFamily = New FontFamily("Lucida Handwriting")
下圖顯示此範例如何在 FlowDocument中呈現。
備註
此建構函式旨在初始化新的 Span 專案,使其包含預先存在的內容選取範圍。