c# - 基于编译指令的 Xamarin 条件 xaml
问题描述
我需要与 XAML 是否有用于调试模式的条件编译器指令相同? 但在 Xamarin xaml 中;我已经尝试了建议的解决方案,但出现此错误:
Type mc:Choice not found in xmlns http://schemas.openxmlformats.org/markup-compatibility/2006
我尝试使用 xcc https://github.com/firstfloorsoftware/xcc,但它似乎不适用于 .netstandard 2.0 / Xamarin.Forms 4.5
解决方案
它在 Xamarin 的 XAML 中略有不同。Xamarin 中有设计时命名空间。
您将使用标记兼容性xml 名称空间并将设计名称空间标记为Ignorable
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:ref="clr-namespace:XamUtilities.Views;assembly=XamUtilities"
mc:Ignorable="d"
x:Class="Sample.MainPage">
<ContentPage.Content>
<d:Label Text="This will be displayed only in previewer"/>
<Label Text="This will be displayed in actual app"/>
</ContentPage.Content>
</ContentPage>
在后面的代码中,您也可以设置值
[DesignTimeVisible (true)]
public partial class MainPage : ContentPage
{
public MainPage ()
{
InitializeComponent ();
if (DesignMode.IsDesignModeEnabled)
{
// Previewer only code
//add your bindings in here
}
}
}
推荐阅读
- c# - 如何在 SQL 合并语句中处理 JSON 数据
- mysql - 在 Node JS 中使用 Sequelize 的动态表名
- rest - 如何在 SwaggerHub 中记录要模拟的 api 调用?
- timezone - 日期是否在 ISO 8601 的目标时区中?
- c# - 如何正确实现 IEnumerable 以返回项目以按属性优先?
- java - ListIterators .next() 即使在 if 条件内也会前进到下一个?
- node.js - 如何在 Cloud Firestore 中同时添加新字段和更新现有字段?
- java - 创建名称为“scopedTarget.contextHeadersBuilder”的 bean 时出错
- python - 在 Python 中按单行/列对 3 维数组进行排序 - 使用矢量化
- go - 如何使用 go 从 gmail 获取未读邮件?