我已经创建了一个Xamarin.Forms解决方案(最新版本的Xamarin和VS 2017 CE),我有针对Android,iOS和UWP的项目 .
我在共享项目中创建了一个用户控件,我试图向它添加一个Entry和一个Picker控件但是我收到一个编译错误,上面写着“Windows Universal项目中不支持Entry” . 和Windows Universal项目中不支持“Picker” . 我在任何文档中都没有发现这些控件与UWP不兼容的说明,我发现人们似乎在UWP项目中非常愉快地使用这些控件 .
我错过了什么吗?如果无法使用这些控件那么Xamarin.Forms有什么意义呢?我认为这是为了防止必须为每个平台创建完全不同的UI .
我的用户控件也在命名空间MyApp.Views中,而xaml的行“xmlns:local =”使用:MyApp.Views“”自动生成 . 这也会产生编译错误:“未定义的命名空间.'using'URI是指无法找到的命名空间'MyApp.Views' . ”这是自动生成的,后面的代码显然在该命名空间中,所以我不清楚这是什么 .
<UserControl
x:Class="MyApp.Views.SomeControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="64"
d:DesignWidth="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Picker x:Name="demographics" Grid.Row="0" Grid.Column="0"></Picker>
<Entry x:Name="filter" Grid.Row="0" Grid.Column="1"></Entry>
</Grid>
</UserControl>
1 回答
请注意,UWP UserControl的Xamarin Forms版本是ContentView .
在“MyApp”项目中创建Xamarin Forms控件,而不是“MyApp.UWP”项目;例:
用法,例如在
MainPage.xaml
项目的MainPage.xaml
中: