Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

MaterialButton: XPE when loading styles with triggers

Đang mở
#413 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
mobile-dev

Hướng nghiên cứu

Tái hiện lỗi bằng cách thêm kiểu MaterialButton được hiển thị vào App.xaml và khởi chạy ứng dụng trên iOS hoặc Android. Sau đó kiểm tra Material.cs quanh GetResource và Color.Secondary, cũng như UI/MaterialButton.cs quanh trình khởi tạo tĩnh của nó; được xem là hoàn tất khi App.InitializeComponent() hoàn thành mà không có XamlParseException được báo cáo.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

🔙 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
Ngôn ngữ chính
C#
Star
631
Fork
150
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Baseflow/XF-Material-Library

Tất cả issue của Baseflow/XF-Material-Library

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.