本文整理汇总了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;
}
示例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);
}
示例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);
}