我需要与XAML是否具有调试模式的条件编译器指令?但在Xamarin-xaml中;我已经尝试了建议的解决方案,但我得到了这个错误:
Type mc:Choice not found in xmlns http://schemas.openxmlformats.org/markup-compatibility/2006
我试过用xcchttps://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
}
}
}