FrameworkContentElement.FindName(String) 方法

定义

查找具有提供的标识符名的元素。Finds an element that has the provided identifier name.

public:
 System::Object ^ FindName(System::String ^ name);
public object FindName (string name);
member this.FindName : string -> obj
Public Function FindName (name As String) As Object

参数

name
String

要搜索的元素的名称。Name of the element to search for.

返回

Object

请求的元素。The requested element. 如果未找到匹配的元素,则可以为 nullMay be null if no matching element was found.

示例

下面的示例在页上引用的元素中设置按名称找到的元素的属性 FlowDocumentThe following example sets a property on an element found by name within a referenced FlowDocument on a page.

void HighlightParagraph(string paraName)
{
    try
    {
        Paragraph wantedNode = (Paragraph)myflowdocument.FindName(paraName);
        if (wantedNode != null)
        {
            wantedNode.Background = Brushes.LightYellow;
        }
    }
    catch { }//handle paragraph not found in UI }
}
Private Sub HighlightParagraph(ByVal paraName As String)
    Try
        Dim wantedNode As Paragraph = CType(myflowdocument.FindName(paraName), Paragraph)
        If wantedNode IsNot Nothing Then
            wantedNode.Background = Brushes.LightYellow
        End If
    Catch 'handle paragraph not found in UI }
    End Try
End Sub

注解

如果此元素包含子元素,则会以递归方式搜索所请求的命名元素的子元素。If this element has child elements, these child elements are all searched recursively for the requested named element.

适用于