當前位置: 首頁>>代碼示例>>C#>>正文


C# PageInfo.TryGetState方法代碼示例

本文整理匯總了C#中System.PageInfo.TryGetState方法的典型用法代碼示例。如果您正苦於以下問題:C# PageInfo.TryGetState方法的具體用法?C# PageInfo.TryGetState怎麽用?C# PageInfo.TryGetState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.PageInfo的用法示例。


在下文中一共展示了PageInfo.TryGetState方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TryGetState_Exception_IncorrectType

        public void TryGetState_Exception_IncorrectType()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");
            navigationEntry.SetState<string>("MyKey", "Test State");

            int result;
            var e = Assert.Throws<InvalidCastException>(() => navigationEntry.TryGetState<int>("MyKey", out result));

            Assert.Equal("Specified cast is not valid.", e.Message);
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:10,代碼來源:PageInfoFixture.cs

示例2: SetState_SameStateKeyOverwritesPreviousValue

        public void SetState_SameStateKeyOverwritesPreviousValue()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<string>("MyKey", "State A");
            navigationEntry.SetState<string>("MyKey", "State B");

            string result;
            bool success = navigationEntry.TryGetState<string>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal("State B", result);
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:13,代碼來源:PageInfoFixture.cs

示例3: TryGetState_ReturnsFalseIfKeyIsUndefined

        public void TryGetState_ReturnsFalseIfKeyIsUndefined()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            string result = "Old Value";
            bool success = navigationEntry.TryGetState<string>("Undefined", out result);

            Assert.Equal(false, success);
            Assert.Equal(null, result);
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:10,代碼來源:PageInfoFixture.cs

示例4: TryGetState_Exception_KeyIsEmpty

        public void TryGetState_Exception_KeyIsEmpty()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            string result;
            var e = Assert.Throws<ArgumentException>(() => navigationEntry.TryGetState<string>("", out result));

            Assert.Equal("The argument cannot be null or an empty string.\r\nParameter name: key", e.Message);
            Assert.Equal("key", e.ParamName);
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:10,代碼來源:PageInfoFixture.cs

示例5: TryGetSetState_Struct_StoresState

        public void TryGetSetState_Struct_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<StructState>("MyKey", new StructState() { Text = "Text Value", Number = 42 });
            StructState result;
            bool success = navigationEntry.TryGetState<StructState>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal("Text Value", result.Text);
            Assert.Equal(42, result.Number);
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:12,代碼來源:PageInfoFixture.cs

示例6: TryGetSetState_Class_StoresNullState

        public void TryGetSetState_Class_StoresNullState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<ClassState>("MyKey", null);
            ClassState result;
            bool success = navigationEntry.TryGetState<ClassState>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal(null, result);
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:11,代碼來源:PageInfoFixture.cs

示例7: TryGetSetState_Int_StoresState

        public void TryGetSetState_Int_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<int>("MyKey", 42);
            int result;
            bool success = navigationEntry.TryGetState<int>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal(42, result);
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:11,代碼來源:PageInfoFixture.cs

示例8: TryGetSetState_String_StoresState

        public void TryGetSetState_String_StoresState()
        {
            PageInfo navigationEntry = new PageInfo("Page Name", "Arguments");

            navigationEntry.SetState<string>("MyKey", "Test State");
            string result;
            bool success = navigationEntry.TryGetState<string>("MyKey", out result);

            Assert.Equal(true, success);
            Assert.Equal("Test State", result);
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:11,代碼來源:PageInfoFixture.cs

示例9: Activate

        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="pageInfo">Information on the arguments and state passed to the page.</param>
        public async void Activate(PageInfo pageInfo)
        {
            // TODO: Create an appropriate data model for your problem domain to replace the sample data

            string groupId = pageInfo.GetArguments<string>();
            var group = await SampleDataSource.GetGroupAsync(groupId);
            this.Group = group;
            this.Items = group.Items;

            // Restore the selected item

            string selectedItemId;

            if (pageInfo.TryGetState<string>("SelectedItem", out selectedItemId))
                SelectedItem = await SampleDataSource.GetItemAsync(selectedItemId);
            else
                SelectedItem = null;
        }
開發者ID:deepakpal9046,項目名稱:Okra.Core,代碼行數:23,代碼來源:SplitViewModel.cs


注:本文中的System.PageInfo.TryGetState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。