MaterialButton: XPE when loading styles with triggers
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- csharp
- 领域
- mobile-dev
调研方向
通过将所示的 MaterialButton 样式添加到 App.xaml 并在 iOS 或 Android 上启动应用来复现该故障。然后检查 GetResource 和 Color.Secondary 附近的 Material.cs,以及其静态初始化器附近的 UI/MaterialButton.cs;当 App.InitializeComponent() 在没有报告的 XamlParseException 的情况下完成时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
🔙 Regression
In our Application we use MaterialButtons to emulate toggle buttons. The default ButtonType is Text.
For Buttons that are toggleable Buttons the ButtonType is set via a Binding and a custom BoolToButtonTypeConverter.
(false->Text, true->Flat)
To invert the TextColor when the Button is toggled on, we use the following style, defined in App.xaml.
<Style TargetType="ui:MaterialButton" ApplyToDerivedTypes="False">
<Style.Triggers>
<Trigger TargetType="ui:MaterialButton" Property="ButtonType" Value="Flat">
<Trigger.Setters>
<Setter Property="TextColor" Value="White"/>
</Trigger.Setters>
</Trigger>
</Style.Triggers>
</Style>
Old (and correct) behavior
The app is initialized without any errors, Buttons behave as expected. (Xamarin.Forms 4.7.0.1142; XF.Material 1.5.8)
Current behavior
The app fails to start with a XamlParseException, as soon as the App-Constructor calls InitializeComponent(). (Xamarin.Forms 5.0.0.1874; XF.Material 1.7.7)
Callstack:
Xamarin.Forms.Xaml.XamlParseException: Position 62:53. Type converter failed: The type initializer for 'XF.Material.Forms.UI.MaterialButton' threw an exception. ---> System.TypeInitializationException: The type initializer for 'XF.Material.Forms.UI.MaterialButton' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object
at XF.Material.Forms.Material.GetResource[T] (System.String key) [0x00000] in C:\Users\mhvdi\Documents\OpenSource\XF-Material-Library\XF.Material\Material.cs:57
at XF.Material.Forms.Material+Color.GetSecondaryColor () [0x00000] in C:\Users\mhvdi\Documents\OpenSource\XF-Material-Library\XF.Material\Material.cs:203
at XF.Material.Forms.Material+Color.get_Secondary () [0x00000] in C:\Users\mhvdi\Documents\OpenSource\XF-Material-Library\XF.Material\Material.cs:198
at XF.Material.Forms.UI.MaterialButton..cctor () [0x0003e] in C:\Users\mhvdi\Documents\OpenSource\XF-Material-Library\XF.Material\UI\MaterialButton.cs:20
--- End of inner exception stack trace ---
at (wrapper managed-to-native) System.Reflection.RuntimeFieldInfo.GetValueInternal(System.Reflection.RuntimeFieldInfo,object)
at System.Reflection.RuntimeFieldInfo.GetValue (System.Object obj) [0x0005e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeFieldInfo.cs:251
at Xamarin.Forms.BindablePropertyConverter.ConvertFrom (System.Type type, System.String propertyName, System.Xml.IXmlLineInfo lineinfo) [0x00055] in D:\a\1\s\Xamarin.Forms.Core\BindablePropertyConverter.cs:99
at Xamarin.Forms.BindablePropertyConverter.Xamarin.Forms.IExtendedTypeConverter.ConvertFromInvariantString (System.String value, System.IServiceProvider serviceProvider) [0x00169] in D:\a\1\s\Xamarin.Forms.Core\BindablePropertyConverter.cs:60
at Xamarin.Forms.Xaml.TypeConversionExtensions.ConvertTo (System.Object value, System.Type toType, System.Func`1[TResult] getConverter, System.IServiceProvider serviceProvider, System.Exception& exception) [0x00041] in D:\a\1\s\Xamarin.Forms.Core\Xaml\TypeConversionExtensions.cs:134
--- End of inner exception stack trace ---
at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.SetPropertyValue (System.Object xamlelement, Xamarin.Forms.Xaml.XmlName propertyName, System.Object value, System.Object rootElement, Xamarin.Forms.Xaml.INode node, Xamarin.Forms.Xaml.HydrationContext context, System.Xml.IXmlLineInfo lineInfo) [0x0007d] in D:\a\1\s\Xamarin.Forms.Xaml\ApplyPropertiesVisitor.cs:366
at Xamarin.Forms.Xaml.ApplyPropertiesVisitor.Visit (Xamarin.Forms.Xaml.ValueNode node, Xamarin.Forms.Xaml.INode parentNode) [0x0007b] in D:\a\1\s\Xamarin.Forms.Xaml\ApplyPropertiesVisitor.cs:60
at Xamarin.Forms.Xaml.ValueNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:91
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00044] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:152
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00044] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:152
at Xamarin.Forms.Xaml.FillResourceDictionariesVisitor.Visit (Xamarin.Forms.Xaml.ElementNode node, Xamarin.Forms.Xaml.INode parentNode) [0x000ec] in D:\a\1\s\Xamarin.Forms.Xaml\FillResourceDictionariesVisitor.cs:57
at Xamarin.Forms.Xaml.ElementNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00012] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:147
at Xamarin.Forms.Xaml.RootNode.Accept (Xamarin.Forms.Xaml.IXamlNodeVisitor visitor, Xamarin.Forms.Xaml.INode parentNode) [0x00079] in D:\a\1\s\Xamarin.Forms.Xaml\XamlNode.cs:211
at Xamarin.Forms.Xaml.XamlLoader.Visit (Xamarin.Forms.Xaml.RootNode rootnode, Xamarin.Forms.Xaml.HydrationContext visitorContext, System.Boolean useDesignProperties) [0x0007e] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:235
at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml, System.Reflection.Assembly rootAssembly, System.Boolean useDesignProperties) [0x000a2] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:104
at Xamarin.Forms.Xaml.XamlLoader.Load (System.Object view, System.String xaml, System.Reflection.Assembly rootAssembly) [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\XamlLoader.cs:78
at Xamarin.Forms.Xaml.Extensions.LoadFromXaml[TXaml] (TXaml view, System.String xaml, System.Reflection.Assembly rootAssembly) [0x00000] in D:\a\1\s\Xamarin.Forms.Xaml\ViewExtensions.cs:49
at Xamarin.Forms.Xaml.ResourcesLoader.CreateFromResource[T] (System.String resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) [0x000b1] in D:\a\1\s\Xamarin.Forms.Xaml\ResourcesLoader.cs:39
at Xamarin.Forms.ResourceDictionary.SetAndLoadSource (System.Uri value, System.String resourcePath, System.Reflection.Assembly assembly, System.Xml.IXmlLineInfo lineInfo) [0x00063] in D:\a\1\s\Xamarin.Forms.Core\ResourceDictionary.cs:76
at Vendor.MobileApp.App.InitializeComponent ()
Reproduction steps
Add the style above into App.xaml and try to launch the App in an Emulator.
Configuration
Version: 1.7.7
Platform:
- 📱 iOS
- 🤖 Android
- 🏁 WPF
- 🌎 UWP
- 🍎 MacOS
- 📺 tvOS
- 🐒 Xamarin.Forms
- 主要语言
- C#
- 星标
- 631
- 派生
- 150
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Baseflow/XF-Material-Library 的其他 Issue
-
难度 5/5 一周以上 新手友好度 20/100
Baseflow/XF-Material-Library#458 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 50/100
Baseflow/XF-Material-Library#457 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 48/100
Baseflow/XF-Material-Library#456 ·
-
难度 3/5 1-2 天 新手友好度 35/100
Baseflow/XF-Material-Library#454 ·
-
难度 1/5 1 小时以内 新手友好度 58/100
Baseflow/XF-Material-Library#453 ·
查看 Baseflow/XF-Material-Library 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
Kryptos-FR/MarkView.Avalonia#105 ·
维护者通常 1 天内回复
-
[辞書]未关闭提案 辞書
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/fluentui-blazor#5410 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
Facepunch/sbox-public#12049 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
EsotericSoftware/spine-runtimes#3185 ·