Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

MaterialButton: XPE when loading styles with triggers

オープン
#413 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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 はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Baseflow/XF-Material-Library のほかの issue

Baseflow/XF-Material-Library の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。