How to use popup defined in App.xaml resources?

I have a popup defined inside App.xaml resources:

<Application.Resources>
        <Popup x:Key="popup">
            //some content here
        </Popup>
   </Application.Resources>

I want to use it this way:

                    Popup popup = this.Resources["popup"] as Popup;
                    popup.IsOpen = true;

For some reason the popup is not showing? Any help is appreciated.

+3
source share
1 answer

, PopUp App.xaml Resources, , . IsOpen true , , PopUp . , PopUp Parent, , InvalidOperationException.

:

popup = App.Current.Resources["popup"] as Popup;
App.Current.Resources.Remove("popup");  // remove the PopUp from the Resource and thus clear his Parent property
ContentPanel.Children.Add(popup);       // add the PopUp to a container inside your page visual tree
popup.IsOpen = true;

, , , - NullReferenceException. , , PopUp , :

popup.IsOpen = false;// PopUp, ContentPanel.Children.Remove( );// App.Current.Resources.Add( " ", );//

, , PopUp, , , PopUp, , , IsOpen.

+5

All Articles