Issue
I'm using XF-Material-Library in my Xamarin.forms, so When I tried to change the default theme of the library by providing an object of type MaterialConfiguration
in the XF.Material.Forms.Material.Init()
method, it keeps throwing exception when trying to open any dialog, even the dialog of the MaterialTextField (with InputType="Choice"
and choices list) which is auto-opens by the library.
here is exception message:
Xamarin.Forms.Xaml.XamlParseException: Position 22:32. StaticResource not found for key Material.Dialog.Width
here is the full exception:
{Xamarin.Forms.Xaml.XamlParseException: Position 22: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.MaterialSimpleDialog.InitializeComponent () [0x00055] in C:\Users\mhvdi\Documents\OpenSource\XF-Material-Library\XF.Material\obj\Release\monoandroid10.0\UI\Dialogs\MaterialSimpleDialog.xaml.g.cs:38 at XF.Material.Forms.UI.Dialogs.MaterialSimpleDialog..ctor (XF.Material.Forms.UI.Dialogs.Configurations.MaterialSimpleDialogConfiguration configuration) [0x00006] in C:\Users\mhvdi\Documents\OpenSource\XF-Material-Library\XF.Material\UI\Dialogs\MaterialSimpleDialog.xaml.cs:21 at XF.Material.Forms.UI.Dialogs.MaterialSimpleDialog.ShowAsync (System.String title, System.Collections.Generic.IEnumerable`1[T] actions, XF.Material.Forms.UI.Dialogs.Configurations.MaterialSimpleDialogConfiguration configuration) [0x00014] in C:\Users\mhvdi\Documents\OpenSource\XF-Material-Library\XF.Material\UI\Dialogs\MaterialSimpleDialog.xaml.cs:31 at UiTest.ViewModels.AboutViewModel.<.ctor>b__17_2 () [0x0006c] in C:\Projects\UiTest\UiTest\UiTest\ViewModels\AboutViewModel.cs:83 }
And here is my code in App.xaml.cs :
XF.Material.Forms.Material.Init(this, new MaterialConfiguration
{
ColorConfiguration = new MaterialColorConfiguration
{
Background = Color.FromHex("#EAEAEA"),
Error = Color.FromHex("#B00020"),
OnBackground = Color.FromHex("#000000"),
OnError = Color.FromHex("#FFFFFF"),
OnPrimary = Color.FromHex("#FFFFFF"),
OnSecondary = Color.FromHex("#FFFFFF"),
OnSurface = Color.FromHex("#000000"),
Primary = Color.FromHex("#2196f3"),
PrimaryVariant = Color.FromHex("#03A9F4"),
Secondary = Color.FromHex("#29b6f6"),
SecondaryVariant = Color.FromHex("#0086c3"),
Surface = Color.FromHex("#FFFFFF")
}
});
Note: for now, I'm only working with Android.
I tried also to use App.xaml to add my configurations as the documentation described, but it didn't work for me, so I have tried to add my configurations in cs file.
Solution
copied from XF-Material_library issues on GitHub that solved by dm-CaT
I've faced the same issue. There is no possibility to avoid it when you're configuring Material from code. You have to configure it via resource dictionary. The steps are:
- Add resources in app.xaml
<Application.Resources>
<mat:MaterialColorConfiguration x:Key="Material.Color"
Background="#e1e1e1"
Error="#B00020"
OnBackground="#2f3232"
OnError="#ffffff"
OnPrimary="#ffffff"
OnSecondary="#2f3232"
OnSurface="#2f3232"
Primary="#585b5b"
PrimaryVariant="#2f3232"
Secondary="#ef7d39"
SecondaryVariant="#ffae67"
Surface="#f5f5f5" />
<mat:MaterialConfiguration x:Key="Material.Configuration" ColorConfiguration="{StaticResource Material.Color}"/>
</Application.Resources>
- Initialize Material in app.xaml.cs before InitializeComponent() call.
- Apply theme from resources to Material after InitializeComponent() call.
Material.Init(this);
InitializeComponent();
Material.Use("Material.Configuration");
Answered By - TameemHabash
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.