【发布时间】:2016-12-26 18:56:53
【问题描述】:
想在 XAML 中为我的标签添加样式,我偶然发现了 Xamarin Developer Guides。
在那里,他们使用绑定到 ContentPage.Resources 的 ResourceDictionary。我试图模仿这一点,编译良好后应用程序启动并返回 NullReferenceException。
我尝试将字典添加到 Grid.Resources 中,但遇到了同样的异常。
我将 Xamarin.Forms v2.3.1.114 与 Prism.Forms v6.2 一起使用,我不知道是哪一个导致了这个问题,或者它是否是由其他原因引起的。
这是我的 XAML:
<?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:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="BetulaApp.Views.MainPage"
Title="MainPage">
<ContentPage.Resources>
<ResourceDictionary>
<Style x:Key="TitleStyle" TargetType="Label">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="30" />
<Setter Property="FontAttributes" Value="Bold" />
<Setter Property="Margin" Value="0,20,0,20" />
</Style>
</ResourceDictionary>
</ContentPage.Resources>
<Grid>
<Label Text="{Binding Title}"
Style="{StaticResource TitleStyle}" />
</Grid>
</ContentPage>
对此事的任何帮助都会很棒!
[E1]添加异常信息:
CallStack 不在加载的模块中。 [外部代码]
在 C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:279,5 C# 的 Xamarin.Forms.Platform.Android.AppCompat.Platform.LayoutRootPage 中的 0x95
在 C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\AppCompat\Platform 的 Xamarin.Forms.Platform.Android.AppCompat.Platform.Xamarin.Forms.Platform.Android.IPlatformLayout.OnLayout 中的 0x12。 cs:196,5 C#
0x20 在 C:\BuildAgent\work\aad494dc9bc9783\Xamarin.Forms.Platform.Android\PlatformRenderer.cs:73,4 C# 的 Xamarin.Forms.Platform.Android.PlatformRenderer.OnLayout 中
Android.Views.ViewGroup.n_OnLayout_ZIIII 中的 0x12,位于 /Users/builder/data/lanes/3540/1cf254db/source/monodroid/src/Mono.Android/platforms/android-23/src/generated/Android.Views。 ViewGroup.cs:3427,4 C#
【问题讨论】:
-
你能添加你的例外吗?
-
@Rohit 抱歉,我应该马上做的。
-
看图太难了,加个栈也行吗?
-
@Rohit 调用堆栈没有加载到模块中,所以这是我能给你的最好的。这是我的 CallStack 窗口的直接副本。
-
尝试移除 setter 中的 margin 属性。
标签: xaml xamarin.forms prism resourcedictionary