TextPointer.CompareTo(TextPointer) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Az aktuális TextPointer és a megadott másodperc által megadott pozíciók közötti sorszám-összehasonlítást hajtja végre TextPointer.
public:
int CompareTo(System::Windows::Documents::TextPointer ^ position);
public int CompareTo(System.Windows.Documents.TextPointer position);
member this.CompareTo : System.Windows.Documents.TextPointer -> int
Public Function CompareTo (position As TextPointer) As Integer
Paraméterek
- position
- TextPointer
Az TextPointer aktuális pozícióhoz viszonyítandó pozíciót meghatározó beállítás.
Válaszok
-1, ha az aktuális TextPointer előzmény; position0, ha a helyek megegyeznek; +1, ha az aktuális TextPointer a positionkövetkező .
Kivételek
position az aktuális pozícióhoz társított szövegtárolón kívüli pozíciót határoz meg.
Példák
Az alábbi példa a metódus használatát mutatja be. A példában a CompareTo metódust a metódussal GetInsertionPosition együtt használjuk annak ellenőrzésére, hogy egy megadott TextElement üres-e.
// Tests to see if the specified TextElement is empty (has no printatble content).
bool IsElementEmpty(TextElement element)
{
// Find starting and ending insertion positions in the element.
// Inward-facing directions are used to make sure that insertion position
// will be found correctly in case when the element may contain inline
// formatting elements (such as a Span or Run that contains Bold or Italic elements).
TextPointer start = element.ContentStart.GetInsertionPosition(LogicalDirection.Forward);
TextPointer end = element.ContentEnd.GetInsertionPosition(LogicalDirection.Backward);
// The element has no printable content if its first and last insertion positions are equal.
return start.CompareTo(end) == 0;
} // End IsEmptyElement method.
' Tests to see if the specified TextElement is empty (has no printatble content).
Private Function IsElementEmpty(ByVal element As TextElement) As Boolean
' Find starting and ending insertion positions in the element.
' Inward-facing directions are used to make sure that insertion position
' will be found correctly in case when the element may contain inline
' formatting elements (such as a Span or Run that contains Bold or Italic elements).
Dim start As TextPointer = element.ContentStart.GetInsertionPosition(LogicalDirection.Forward)
Dim [end] As TextPointer = element.ContentEnd.GetInsertionPosition(LogicalDirection.Backward)
' The element has no printable content if its first and last insertion positions are equal.
Return start.CompareTo([end]) = 0
End Function ' End IsEmptyElement method.
Megjegyzések
A -1 értéke azt jelzi, hogy az aktuális TextPointer pozíció megelőzi a megadott pozíciót position. A 0 érték azt jelzi, hogy a megadott pozíciók egyenlőek. A pozitív +1 érték azt jelzi, hogy az áram TextPointer által megadott pozíció a megadott pozíciót positionköveti.