Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XamlParseException because of custom MaterialConfiguration #457

Open
2 of 7 tasks
ganyuss opened this issue Jul 14, 2023 · 1 comment
Open
2 of 7 tasks

XamlParseException because of custom MaterialConfiguration #457

ganyuss opened this issue Jul 14, 2023 · 1 comment

Comments

@ganyuss
Copy link

ganyuss commented Jul 14, 2023

🐛 Bug Report

Whenever I set a custom MaterialConfiguration, sizes are broken. The MaterialLabel font sizes are all default sizes, and when I open an alert, I get this exception:

Xamarin.Forms.Xaml.XamlParseException: Position 19:32. StaticResource not found for key Material.Dialog.Width
  at Xamarin.Forms.Xaml.StaticResourceExtension.ProvideValue (System.IServiceProvider serviceProvider) [0x0008f] in D:\a\1\s\Xamarin.Forms.Xaml\MarkupExtensions\StaticResourceExtension.cs:27 
  at XF.Material.Forms.UI.Dialogs.MaterialAlertDialog.InitializeComponent () [0x00066] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\obj\Release\monoandroid10.0\UI\Dialogs\MaterialAlertDialog.xaml.g.cs:42 
  at XF.Material.Forms.UI.Dialogs.MaterialAlertDialog..ctor (XF.Material.Forms.UI.Dialogs.Configurations.MaterialAlertDialogConfiguration configuration) [0x00006] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\UI\Dialogs\MaterialAlertDialog.xaml.cs:32 
  at XF.Material.Forms.UI.Dialogs.MaterialAlertDialog..ctor (System.String message, System.String title, System.String action1Text, System.String action2Text, XF.Material.Forms.UI.Dialogs.Configurations.MaterialAlertDialogConfiguration configuration) [0x00000] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\UI\Dialogs\MaterialAlertDialog.xaml.cs:12 
  ...

This is due to the "addDefaults" parameter to the Material class' constructor. It stops the flow from setting up size resources whenever a custom config is provided.

if (addDefaults)
{
if (config == null)
{
if (!_res.MergedDictionaries.Contains((defaultColors.Value)))
_res.MergedDictionaries.Add(defaultColors.Value);
if (!_res.MergedDictionaries.Contains((defaultTypos.Value)))
_res.MergedDictionaries.Add(defaultTypos.Value);
}
if (!_res.MergedDictionaries.Contains((defaultSizes.Value)))
_res.MergedDictionaries.Add(defaultSizes.Value);
}

Expected behavior

XF.Material.Forms.Material.Init should setup sizes correctly when custom configs are set.

Reproduction steps

Add this to app resources:

        <resources:MaterialColorConfiguration x:Key="Material.Color"
                                              Background="#EAEAEA"
                                              Error="#B00020"
                                              OnBackground="#000000"
                                              OnError="#FFFFFF"
                                              OnPrimary="#ffffff"
                                              OnSecondary="#FFFFFF"
                                              OnSurface="#000000"
                                              Primary="{StaticResource PrimaryColor}"
                                              PrimaryVariant="#ffdbcd"
                                              Secondary="#4e6704"
                                              SecondaryVariant="#cfee82"
                                              Surface="#FFFFFF" />
        
        <resources:MaterialConfiguration x:Key="Material.Configuration"
                                    ColorConfiguration="{StaticResource Material.Color}" />                                    

And init the package like this:

XF.Material.Forms.Material.Init(this, (MaterialConfiguration)Resources["Material.Configuration"]);

Configuration

Version: 1.8.0

Platform:

  • 📱 iOS
  • 🤖 Android
  • 🏁 WPF
  • 🌎 UWP
  • 🍎 MacOS
  • 📺 tvOS
  • 🐒 Xamarin.Forms
@ganyuss
Copy link
Author

ganyuss commented Jul 14, 2023

Besides, on Android, initialising with XF.Material.Forms.Material.Init(this, new MaterialConfiguration()); breaks the app. On app open I get

System.InvalidOperationException: Invalid on Color.Default
  at Xamarin.Forms.Color.MultiplyAlpha (System.Double alpha) [0x00019] in D:\a\1\s\Xamarin.Forms.Core\Color.cs:151 
  at XF.Material.Droid.Renderers.MaterialButtonRenderer.SetTextColors () [0x0005c] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\Platforms\Android\Renderers\MaterialButtonRenderer.cs:89 
  at XF.Material.Droid.Renderers.MaterialButtonRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1[TElement] e) [0x000b2] in Z:\Documents\OpenSource\XF-Material-Library\XF.Material\Platforms\Android\Renderers\MaterialButtonRenderer.cs:55 
  ... 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant