Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
 /// <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);
     });
 }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
 /// <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;
 }
Exemplo n.º 6
0
 /// <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;
     });
 }