gpt4 book ai didi

silverlight - 如何获取 UIElement 的父弹出窗口?

转载 作者:行者123 更新时间:2023-12-04 19:53:28 24 4
gpt4 key购买 nike

我对下面的标记有两个问题:

<Popup>
<Button x:Name="button"/>
</Popup>
  • 为什么VisualTreeHelper.GetParent(button)返回空?
  • 我怎样才能得到父级 PopupUIElement ?
  • 最佳答案

    而不是通过 VisualTree ,您是否刚刚尝试了一个 while 循环来遍历元素的 .Parents ?

        private void TryClosePopupParent(object o)
    {
    while (o != null)
    {
    Popup p = (o as Popup);
    if(p == null)
    {
    o = (o as FrameworkElement).Parent;
    }
    else
    {
    p.IsOpen = false;
    break;
    }
    }
    }

    我从来没有在没有 PopUp 的东西上测试过它。作为 parent ,但这对我有用。

    关于silverlight - 如何获取 UIElement 的父弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2007550/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com