【发布时间】:2018-01-09 23:08:51
【问题描述】:
我创建了一个 Xamarin.Forms 解决方案(最新版本的 Xamarin 和 VS 2017 CE),并且我有针对 Android、iOS 和 UWP 的项目。
我在共享项目中创建了一个用户控件,并尝试向其中添加一个条目和一个选取器控件,但我收到一个编译错误,提示“Windows 通用项目中不支持条目”。和“Windows 通用项目不支持选取器。”。我在任何文档中都找不到任何迹象表明这些控件与 UWP 不兼容,并且我发现人们似乎在 UWP 项目中非常愉快地使用这些控件的示例。
我错过了什么吗?如果无法使用这些控件,那么 Xamarin.Forms 的意义何在?我认为这是为了避免必须为每个平台创建完全不同的 UI。
此外,我的用户控件位于命名空间 MyApp.Views 中,并且 xaml 具有自动生成的“xmlns:local="using:MyApp.Views"" 行。这也会产生一个编译错误:“未定义的命名空间。‘使用’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>
【问题讨论】:
-
这是 IDE 中的错误、编译错误还是运行时错误?您的用户控制在共享项目中吗?
-
这是一个编译错误。用户控制在共享项目中。
-
请贴出相关代码和具体报错信息
-
我在帖子中发布了确切的错误消息。 xaml 只是基本的
等。 -
您正在尝试将 XF XAML 与 UWP 用户控件混合。这不是它的工作原理
标签: xamarin.forms