how to get the children of an element WPF

前端 未结 2 1703
栀梦
栀梦 2020-12-09 20:36

I have a stackpanel that contains an Image and a TextBlock. I\'m raising an event once double click is being performed by the user.(P.S - I\'m adding the St

2条回答
  •  伪装坚强ぢ
    2020-12-09 21:00

    A simple way of getting the first child element of a certain type (e.g. TextBlock) is this:

    var textBlock = panel.Children.OfType().FirstOrDefault();
    

    You either get the first TextBlock or null if there isn't any.

提交回复
热议问题