简体   繁体   English

我们可以在 c# 后面的代码中检索 XAML UI 代码吗?

[英]Can we retrive XAML UI Code in code behind c#?

I have created a control and have added to ContentPage.Content in C#.我创建了一个控件并添加到 C# 中的 ContentPage.Content 中。 Now can we retrieve XAML complete UI code from the Content?现在我们可以从内容中检索 XAML 完整的 UI 代码吗? I have to save this Xamarin form ui code in PostgreSQL database.我必须将这个 Xamarin 表单 ui 代码保存在 PostgreSQL 数据库中。

StackLayout parent = null; StackLayout 父级 = null;

Add any children (label, entry etc.) in the parent.在父级中添加任何子级(标签、条目等)。

Content = new ScrollView { Content = parent };内容 = 新的 ScrollView { 内容 = 父 };

Then get xaml code from Content.然后从 Content 中获取 xaml 代码。 Is it possible?可能吗?

I think you are looking for XamlWriter which is not available in Xamarin.Forms.我认为您正在寻找 Xamarin.Forms 中不可用的 XamlWriter。 The only thing you can actually do is to read and parse a XAML string, but that is just the opposite of your goal.您实际上唯一可以做的就是读取和解析 XAML 字符串,但这与您的目标相反。

You can however serialize your XF view and save it to database.但是,您可以序列化您的 XF 视图并将其保存到数据库中。 Plain serialization will generate a ton of trash (properties) you don't actually need, but instead you could create your own serialization mechanism to generate a simple model with just the view properties you need.普通序列化会生成大量您实际上不需要的垃圾(属性),但是您可以创建自己的序列化机制来生成一个简单的 model ,其中只包含您需要的视图属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM