当前位置: 首页>>代码示例>>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;未经允许,请勿转载。