/// <summary>Registers a frame so that its navigation state can be saved and restored. </summary> /// <param name="frame">The frame. </param> /// <param name="sessionStateKey">The session state key. </param> public static void RegisterFrame(MtFrame frame, String sessionStateKey) { if (frame.GetValue(FrameSessionStateKeyProperty) != null) { throw new InvalidOperationException("Frames can only be registered to one session state key"); } if (frame.GetValue(FrameSessionStateProperty) != null) { throw new InvalidOperationException("Frames must be either be registered before accessing frame session state, or not registered at all"); } frame.SetValue(FrameSessionStateKeyProperty, sessionStateKey); _registeredFrames.Add(new WeakReference <MtFrame>(frame)); RestoreFrameNavigationState(frame); }
/// <summary>Deregisters a frame. </summary> /// <param name="frame">The frame. </param> public static void DeregisterFrame(MtFrame frame) { SessionState.Remove((String)frame.GetValue(FrameSessionStateKeyProperty)); _registeredFrames.RemoveAll((weakFrameReference) => { MtFrame testFrame; return(!weakFrameReference.TryGetTarget(out testFrame) || testFrame == frame); }); }
/// <summary>Gets the session state for a given frame. </summary> /// <param name="frame">The frame. </param> /// <returns>The session state. </returns> public static Dictionary <String, Object> SessionStateForFrame(MtFrame frame) { var frameState = (Dictionary <String, Object>)frame.GetValue(FrameSessionStateProperty); if (frameState == null) { var frameSessionKey = (String)frame.GetValue(FrameSessionStateKeyProperty); if (frameSessionKey != null) { if (!_sessionState.ContainsKey(frameSessionKey)) { _sessionState[frameSessionKey] = new Dictionary <String, Object>(); } frameState = (Dictionary <String, Object>)_sessionState[frameSessionKey]; } else { frameState = new Dictionary <String, Object>(); } frame.SetValue(FrameSessionStateProperty, frameState); } return(frameState); }
/// <summary>Registers a frame so that its navigation state can be saved and restored. </summary> /// <param name="frame">The frame. </param> /// <param name="sessionStateKey">The session state key. </param> public static void RegisterFrame(MtFrame frame, String sessionStateKey) { if (frame.GetValue(FrameSessionStateKeyProperty) != null) throw new InvalidOperationException("Frames can only be registered to one session state key"); if (frame.GetValue(FrameSessionStateProperty) != null) throw new InvalidOperationException("Frames must be either be registered before accessing frame session state, or not registered at all"); frame.SetValue(FrameSessionStateKeyProperty, sessionStateKey); _registeredFrames.Add(new WeakReference<MtFrame>(frame)); RestoreFrameNavigationState(frame); }
/// <summary>Gets the session state for a given frame. </summary> /// <param name="frame">The frame. </param> /// <returns>The session state. </returns> public static Dictionary<String, Object> SessionStateForFrame(MtFrame frame) { var frameState = (Dictionary<String, Object>)frame.GetValue(FrameSessionStateProperty); if (frameState == null) { var frameSessionKey = (String)frame.GetValue(FrameSessionStateKeyProperty); if (frameSessionKey != null) { if (!_sessionState.ContainsKey(frameSessionKey)) _sessionState[frameSessionKey] = new Dictionary<String, Object>(); frameState = (Dictionary<String, Object>)_sessionState[frameSessionKey]; } else frameState = new Dictionary<String, Object>(); frame.SetValue(FrameSessionStateProperty, frameState); } return frameState; }
/// <summary>Deregisters a frame. </summary> /// <param name="frame">The frame. </param> public static void DeregisterFrame(MtFrame frame) { SessionState.Remove((String)frame.GetValue(FrameSessionStateKeyProperty)); _registeredFrames.RemoveAll((weakFrameReference) => { MtFrame testFrame; return !weakFrameReference.TryGetTarget(out testFrame) || testFrame == frame; }); }