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


C# ContentPage.LoadFromXaml方法代碼示例

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


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

示例1: App

        public App()
        {
            var content = new ContentPage ();

            var stream = this.GetType ().GetTypeInfo ().Assembly.GetManifestResourceStream ("DynamicFormsDemo.Main.xaml");
            var xaml = new StreamReader (stream).ReadToEnd ();
            content.LoadFromXaml (xaml);

            stream = this.GetType ().GetTypeInfo ().Assembly.GetManifestResourceStream ("DynamicFormsDemo.Main.json");
            var json = new StreamReader (stream).ReadToEnd ();
            var model = JModel.Parse (json);

            content.BindingContext = model;

            MainPage = content;
        }
開發者ID:ReedCopsey,項目名稱:DynamicForms,代碼行數:16,代碼來源:App.cs

示例2: when_loading_xaml_then_sets_bound_data

        public void when_loading_xaml_then_sets_bound_data()
        {
            // Get Xaml from somewhere (i.e. VS)
            var xaml = @"<ContentPage xmlns='http://xamarin.com/schemas/2014/forms'
             xmlns:x='http://schemas.microsoft.com/winfx/2009/xaml'>
            <Label Text='{Binding Title, Mode=TwoWay}' VerticalOptions='Center' HorizontalOptions='Center' />
            </ContentPage> ";

            var model = new DictionaryModel(new Dictionary<string, object>
            {
                { "Title", "Bar" }
            });

            // Create empty container page for the XAML
            //		TODO: ensure the root element in the Xaml is actually a ContentPage?
            var view = new ContentPage ();

            // Set binding context to dummy data
            view.BindingContext = model;

            // Load the Xaml into the View
            view.LoadFromXaml (xaml);

            // Grab the new label control added to the view via Xaml
            var label = view.Content as Label;
            Assert.NotNull (label);

            // UI properly bound to underlying model!
            Assert.Equal ("Bar", label.Text);

            // Change the label text via the control
            label.Text = "Foo";

            // Underlying model is updated!
            Assert.Equal ("Foo", model["Title"]);

            // Change the underlying model is
            model["Title"] = "Bar";

            // UI label properly reflecting underlying model change!
            Assert.Equal("Bar", label.Text);
        }
開發者ID:ReedCopsey,項目名稱:DynamicForms,代碼行數:42,代碼來源:DictionaryModelSpec.cs

示例3: when_loading_xaml_then_sets_bound_data_to_complex_model

        public void when_loading_xaml_then_sets_bound_data_to_complex_model()
        {
            // Get Xaml from somewhere (i.e. VS)
            var xaml = @"<ContentPage xmlns='http://xamarin.com/schemas/2014/forms'
             xmlns:x='http://schemas.microsoft.com/winfx/2009/xaml'>
            <Label Text='{Binding Address.Phone.Prefix, Mode=TwoWay}' VerticalOptions='Center' HorizontalOptions='Center' />
            </ContentPage> ";

            // Get dummy data from somewhere (i.e. VS)
            var model = new DictionaryModel(new Dictionary<string, object>
            {
                { "Name", "Xamarin" },
                { "Address", new Dictionary<string, object>
                    {
                        {  "Street", "Camila" },
                        {  "Phone", new Dictionary<string, object>
                            {
                                { "Prefix", "+54" },
                                { "Area", "11" },
                            }
                        },
                    }
                }
            });

            // Create empty container page for the XAML
            //		TODO: ensure the root element in the Xaml is actually a ContentPage?
            var view = new ContentPage ();

            // Set binding context to dummy data
            view.BindingContext = model;

            // Load the Xaml into the View
            //		TODO: this method is internal in XF.Xaml
            view.LoadFromXaml(xaml);

            // Grab the new label control added to the view via Xaml
            var label = view.Content as Label;
            Assert.NotNull (label);

            // UI properly bound to underlying model!
            Assert.Equal ("+54", label.Text);

            // Change the label text via the control
            label.Text = "+1";

            // Underlying model is updated!
            dynamic data = model;

            Assert.NotNull ((object)data.Address);
            Assert.NotNull ((object)data.Address.Phone);
            Assert.NotNull ((object)data.Address.Phone.Prefix);
            Assert.Equal ("+1", (string)data.Address.Phone.Prefix);

            // Change underlying data model
            data.Address.Phone.Prefix = "+54";

            Assert.Equal ("+54", label.Text);
        }
開發者ID:ReedCopsey,項目名稱:DynamicForms,代碼行數:59,代碼來源:DictionaryModelSpec.cs


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