我正在寻找一种解决方案,在Xamarin.Forms中动态加载XAML文件,以便将其显示为视图/ContentPage。我已经找到了一些解决这个问题的答案,但它们不再起作用或示例已被删除:Xamarin forms.Dynamically load a page。
https://forums.xamarin.com/discussion/87727/load-xaml-dynamically-at-runtime
加载XAML示例:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Examples.Views.TestView">
<ContentPage.Resources>
<ResourceDictionary>
<Style TargetType="Label">
<Setter Property="FontSize" Value="Medium" />
<Setter Property="TextColor" Value="Black"/>
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<ContentPage.Content>
<StackLayout>
<Label Text="Hello World!"></Label>
</StackLayout>
</ContentPage.Content>
</ContentPage>