单击WPF中的“用户控制"按钮时,弹出窗口未关闭 [英] Pop up is not closed on clicking of User control button In WPF

查看:135
本文介绍了单击WPF中的“用户控制"按钮时,弹出窗口未关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击用户控件中的图标打开弹出窗口

Opening pop up on click of icon in user control

<Popup x:Name="pp1" Placement="Center" AllowsTransparency="False"

PlacementTarget ="" {Binding ElementName = grdCT}"

Closed =" pp1_Closed"; StaysOpen ="false" PopupAnimation ="Slide" > < local:FDataControl x:Name ="controlFDataControl" Background ="White" BorderThickness ="2".宽度="388"/>

Closed="pp1_Closed" StaysOpen="false" PopupAnimation="Slide" > <local:FDataControl x:Name="controlFDataControl"Background="White" BorderThickness="2" Width="388"/>

在弹出窗口打开时,它具有一个用户控件,该用户控件具有关闭弹出窗口的按钮,我想通过单击该弹出的用户控件的关闭按钮来关闭该弹出窗口.我尝试用staysopen = false和Isopen = true尝试使用,请提示

In when pop up opens it have one user control which have button to close pop up i want to close this pop up by clicking on close button of that popuped User control. i tried with staysopen=false and Isopen=true Please suggest that will ne needfull


推荐答案

如果关闭按钮位于FDataControl中,则可以使用LogicalTreeHelper类和然后将其IsOpen属性设置为false:

If the close button is located in the FDataControl, you could get a reference to the Popup using the LogicalTreeHelper class and then set its IsOpen property to false:

private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            var popup = FindParent<Popup>(sender as Button);
            if (popup != null)
                popup.IsOpen = false;
        }

        private static T FindParent<T>(DependencyObject dependencyObject) where T : DependencyObject
        {
            var parent = LogicalTreeHelper.GetParent(dependencyObject);

            if (parent == null) return null;

            var parentT = parent as T;
            return parentT ?? FindParent<T>(parent);
        }

希望有帮助.

请通过将所有有用的帖子标记为答案来关闭该主题,如果您有新问题,请开始一个新主题.请不要在同一线程中问几个问题.

Please close this thread by marking all helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于单击WPF中的“用户控制"按钮时,弹出窗口未关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆