@@ -127,9 +127,9 @@ private void InvalidatePopup()
127127 {
128128 _isDirty = false ;
129129 }
130- if ( Popup != null )
130+ if ( CurrentPopup != null )
131131 {
132- _ = await Popup . EvaluateExpressionsAsync ( ) ;
132+ _ = await CurrentPopup . EvaluateExpressionsAsync ( ) ;
133133 }
134134 }
135135 catch
@@ -138,14 +138,11 @@ private void InvalidatePopup()
138138 } ) ;
139139 }
140140
141- private bool _isNavigating = false;
142-
143141 private void SubView_OnNavigating( object ? sender , NavigationSubView . NavigationEventArgs e )
144142 {
145143 if ( e . Cancel )
146144 return;
147145
148- _isNavigating = true;
149146 if ( e . NavigatingTo is Popup to )
150147 {
151148 SetCurrentPopup( to ) ;
@@ -158,35 +155,57 @@ private void SubView_OnNavigating(object? sender, NavigationSubView.NavigationEv
158155 SetCurrentPopup( previousPopup ) ;
159156 }
160157 }
161- _isNavigating = false;
158+ }
159+
160+
161+ #if WINDOWS_XAML
162+ private static readonly DependencyProperty CurrentPopupProperty =
163+ DependencyProperty. Register ( nameof ( CurrentPopup ) , typeof ( Popup ) , typeof ( PopupViewer ) , new PropertyMetadata ( null ) ) ;
164+ #elif MAUI
165+ private Popup? _currentPopup ;
166+ #elif WPF
167+ private static readonly DependencyPropertyKey CurrentPopupPropertyKey =
168+ DependencyProperty. RegisterReadOnly (
169+ name : nameof ( CurrentPopup ) ,
170+ propertyType : typeof ( Popup ) ,
171+ ownerType : typeof ( PopupViewer ) ,
172+ typeMetadata : new FrameworkPropertyMetadata ( ) ) ;
173+ #endif
174+ private Popup? GetCurrentPopup ( )
175+ {
176+ #if WINDOWS_XAML
177+ return ( Popup ? ) GetValue( CurrentPopupProperty ) ;
178+ #elif WPF
179+ return ( Popup ? ) GetValue ( CurrentPopupPropertyKey . DependencyProperty ) ;
180+ #elif MAUI
181+ return _currentPopup;
182+ #endif
162183 }
163184
164185 private void SetCurrentPopup ( Popup ? value )
165186 {
166- var oldValue = Popup ;
187+ var oldValue = CurrentPopup ;
167188 if ( oldValue ! = value )
168189 {
169- SetValue( PopupProperty , value ) ;
190+ #if WINDOWS_XAML
191+ SetValue ( CurrentPopupProperty , value ) ;
192+ #elif WPF
193+ SetValue ( CurrentPopupPropertyKey , value ) ;
194+ #elif MAUI
195+ _currentPopup = value ;
196+ OnPropertyChanged( nameof ( CurrentPopup ) ) ;
197+ #endif
198+ OnCurrentPopupPropertyChanged( oldValue , value ) ;
170199 }
171200 }
172201
173- /// <summary>
174- /// Gets or sets the associated Popup.
175- /// </summary>
176- public Popup? Popup
202+ private void OnCurrentPopupPropertyChanged( Popup ? oldPopup , Popup ? newPopup )
177203 {
178- get { return GetValue ( PopupProperty ) as Popup ; }
179- set { SetValue ( PopupProperty , value ) ; }
180- }
181-
182- /// <summary>
183- /// Identifies the <see cref="PopupManager"/> dependency property.
184- /// </summary>
185- public static readonly DependencyProperty PopupProperty =
186- PropertyHelper . CreateProperty < Popup , PopupViewer > ( nameof ( Popup ) , null , ( s , oldValue , newValue ) => s . OnPopupPropertyChanged ( oldValue , newValue ) ) ;
204+ if ( newPopup is not null )
205+ {
206+ InvalidatePopup( ) ;
207+ }
187208
188- private void OnPopupPropertyChanged( Popup ? oldPopup , Popup ? newPopup )
189- {
190209 if ( oldPopup ? . GeoElement is not null )
191210 {
192211 _dynamicEntityChangedListener? . Detach ( ) ;
@@ -216,11 +235,43 @@ private void OnPopupPropertyChanged(Popup? oldPopup, Popup? newPopup)
216235
217236 }
218237 }
219- if ( ! _isNavigating && GetTemplateChild ( "SubFrameView" ) is NavigationSubView subView )
238+ InvalidatePopup( ) ;
239+ }
240+
241+ /// <summary>
242+ /// Gets the currently active popup being viewed
243+ /// </summary>
244+ /// <remarks>
245+ /// If you are viewing related features or utility network associations, this will return the currently active popup being viewed.
246+ /// </remarks>
247+ /// <seealso cref="Popup"/>
248+ public Popup? CurrentPopup
249+ {
250+ get => GetCurrentPopup( ) ;
251+ }
252+
253+ /// <summary>
254+ /// Gets or sets the associated Popup.
255+ /// </summary>
256+ /// <seealso cref="CurrentPopup"/>
257+ public Popup? Popup
258+ {
259+ get { return GetValue ( PopupProperty ) as Popup ; }
260+ set { SetValue ( PopupProperty , value ) ; }
261+ }
262+
263+ /// <summary>
264+ /// Identifies the <see cref="Popup"/> dependency property.
265+ /// </summary>
266+ public static readonly DependencyProperty PopupProperty =
267+ PropertyHelper . CreateProperty < Popup , PopupViewer > ( nameof ( Popup ) , null , ( s , oldValue , newValue ) => s . OnPopupPropertyChanged ( oldValue , newValue ) ) ;
268+
269+ private void OnPopupPropertyChanged( Popup ? oldPopup , Popup ? newPopup )
270+ {
271+ if ( GetTemplateChild ( "SubFrameView" ) is NavigationSubView subView )
220272 {
221- _ = subView. Navigate ( content : Popup , clearNavigationStack : Popup is null , skipRaisingEvent : true ) ;
273+ _ = subView. Navigate ( content : Popup , clearNavigationStack : true ) ;
222274 }
223- InvalidatePopup( ) ;
224275 }
225276
226277 /// <summary>
0 commit comments