【发布时间】:2017-07-21 15:08:16
【问题描述】:
我搜索了 SO 以找到 this 问题,但答案对我不起作用,因此问题仍然存在。
就个人而言,我认为该问题可能与某些配置“事物”有关,但我不知道从哪里开始寻找解决它。据我所知,我没有改变任何超出规范的配置设置(只是使用了标准的新项目方法)。以下是关于我的问题的一些详细信息:
恰好今天是第一次尝试 XamlC 功能。起初我在我的 App.cs 文件中尝试了程序集级属性:
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
编译后,我得到了一堆完全相同的错误。在使用 TemplateControl 的任何页面上,我也遇到了不同的错误。所以我把它从程序集级别上拉下来,把一个类级别的属性放在一个页面上,它仍然失败并出现同样的错误:
Value cannot be null.
Parameter name: method
我在 Stackoverflow 上四处寻找,发现大约一年前有人遇到了同样的问题(在这里),但他们说他们通过将 Xam Forms 升级到最新版本解决了这个问题。由于我使用的是最新的稳定版本,所以我无处可去。
我在我的应用程序的几个页面上尝试了这个类级属性,但发现它只能在我整个应用程序的一个页面上工作......恰好这个页面在 XAML 标记中的绑定为零。我想知道是否引入了导致它崩溃的错误。
无效的页面标记:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Prepify.App.Pages.MainMenu"
xmlns:controls="clr-namespace:ImageCircle.Forms.Plugin.Abstractions;assembly=ImageCircle.Forms.Plugin.Abstractions"
BackgroundColor="White"
Title="Menu">
<StackLayout VerticalOptions="FillAndExpand">
<ListView
Header="{Binding .}"
SeparatorColor="{StaticResource dividerColor}"
HasUnevenRows="True"
ItemSelected="AppMenu_OnItemSelected"
ItemTapped="AppMenu_OnItemTapped"
ItemsSource="{Binding Items}"
x:Name="appMenu">
<ListView.HeaderTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="10"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="80"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="5"/>
</Grid.RowDefinitions>
<BoxView Grid.ColumnSpan="4" Grid.RowSpan="4" BackgroundColor="{StaticResource grayDark}"/>
<controls:CircleImage Grid.Column="1" Grid.Row="1" HorizontalOptions="Start" VerticalOptions="End" Source="{Binding ProfileImageUrl}" WidthRequest="75" HeightRequest="75"/>
<Label Grid.Column="1" Grid.Row="2" Text="{Binding FullName}"/>
<ActivityIndicator Grid.Column="2" Grid.Row="2" IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}" Color="White" WidthRequest="20" HeightRequest="20" VerticalOptions="Center" />
</Grid>
</DataTemplate>
</ListView.HeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal" >
<StackLayout.Padding>
<OnPlatform x:TypeArguments="Thickness" Android="15,15,15,15" iOS="25,12,15,12" />
</StackLayout.Padding>
<Image Source="{Binding Icon}" VerticalOptions="Center" WidthRequest="20" HeightRequest="20"/>
<Image WidthRequest="20"/>
<Label Text="{Binding Label}" VerticalOptions="Center" TextColor="{Binding LabelColor}" Style="{DynamicResource ListItemTextStyle}"/>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
</ContentPage>
唯一有效页面的标记(注意,任何地方都没有绑定):
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Prepify.App.Pages.Root"
xmlns:pages="clr-namespace:Prepify.App.Pages;assembly=Prepify.App"
MasterBehavior="Popover"
Title="Make Preparedness Easy">
<MasterDetailPage.Master>
<pages:MainMenu/>
</MasterDetailPage.Master>
</MasterDetailPage>
我正在使用发布此问题时的所有最新版本。 视觉工作室 2015 Xamarin.Forms 2.3.3.193 Xamarin.VS 4.3.0.784
【问题讨论】:
标签: .net xaml xamarin xamarin.forms