كيفية القيام بما يلي: استخدام زخرفة النص مع ارتباط تشعبي

كائن Hyperlink هو عنصر محتوى تدفق مستوى مضمّن تسمح لك باستضافة الارتباطات التشعبية داخل محتوى التدفق. By الافتراضي, Hyperlink uses a TextDecoration object إلى display an underline. TextDecoration objects can be performance intensive إلى instantiate, particularly if you have many Hyperlink objects. إذا قمت بإجراء استخدام شامل لعناصر Hyperlink قد تحتاج إلى الأخذ بعين الاعتبار إظهار تسطير فقط عند تشغيل أحد الأحداث مثل حدث MouseEnter.

في المثال التالي، التسطير للارتباط "MSN الخاص بي" حيوي — يظهر فقط عند تشغيل حدث MouseEnter.

تعريف الارتباطات التشعبية ب TextDecorations

الارتباطات التشعبية التي تعرض TextDecorations

مثال

يبين نموذج العلامات التالي Hyperlink معرّف مع وبدون تسطير:

<!-- Hyperlink with default underline. -->
<Hyperlink NavigateUri="https://www.msn.com">
  MSN Home
</Hyperlink>

<Run Text=" | " />

<!-- Hyperlink with no underline. -->
<Hyperlink Name="myHyperlink" TextDecorations="None"
           MouseEnter="OnMouseEnter"
           MouseLeave="OnMouseLeave"
           NavigateUri="https://www.msn.com">
  My MSN
</Hyperlink>

نموذج التعليمات البرمجية التالية يوضح كيفية إنشاء تسطير إلى Hyperlink على حدث MouseEnter، إزالته على الحدث MouseLeave.

        ' Display the underline on only the MouseEnter event.
        Private Overloads Sub OnMouseEnter(ByVal sender As Object, ByVal e As EventArgs)
            myHyperlink.TextDecorations = TextDecorations.Underline
        End Sub

        ' Remove the underline on the MouseLeave event.
        Private Overloads Sub OnMouseLeave(ByVal sender As Object, ByVal e As EventArgs)
            myHyperlink.TextDecorations = Nothing
        End Sub
// Display the underline on only the MouseEnter event.
private void OnMouseEnter(object sender, EventArgs e)
{
    myHyperlink.TextDecorations = TextDecorations.Underline;
}

// Remove the underline on the MouseLeave event.
private void OnMouseLeave(object sender, EventArgs e)
{
    myHyperlink.TextDecorations = null;
}

راجع أيضًا:

المهام

كيفية القيام بما يلي: إنشاء زخرفة للنص

المرجع

TextDecoration

Hyperlink

المبادئ

تحسين أداء تطبيق WPF