Hello,
You new a frame in the GetControlsGroupMainFrameStyle
method, and set ControlsGroupMainFrameStyle = _Frame.Style;
, but the _Frame.Style
is null.
(Note: Because you get the device info in MainThread, and then set the style for Frame, it will cost a few seconds to load the page)
public static Style GetControlsGroupMainFrameStyle()
{
MainThread.BeginInvokeOnMainThread(() =>
{...
//assign MyFrame style to the ControlsGroupMainFrame
// ControlsGroupMainFrameStyle = _Frame.Style;
ControlsGroupMainFrameStyle = new Style(typeof(Frame))
{
Setters =
{
new Setter
{
Property = Frame.BorderColorProperty,
Value = Color.FromArgb("#4c4c4c")
},
new Setter
{
Property = Frame.MarginProperty,
Value = new Thickness(0, 0, 0, 5),
},
new Setter
{
Property = Frame.BackgroundColorProperty,
Value = Colors.Green
},
new Setter
{
Property = Frame.BorderColorProperty,
Value = Color.FromArgb("#4c4c4c")
},
new Setter
{
Property = Frame.PaddingProperty,
Value = 0
},
new Setter
{
Property = Frame.CornerRadiusProperty,
Value = 5
},
new Setter
{
Property = Frame.HasShadowProperty,
Value = true
},
new Setter
{
Property = Frame.HorizontalOptionsProperty,
Value = _Frame.HorizontalOptions
},
new Setter
{
Property = Frame.WidthRequestProperty,
Value = _Frame.WidthRequest
},
new Setter
{
Property = Frame.MinimumWidthRequestProperty,
Value = _Frame.MinimumWidthRequest
}
}
};
});
//return style
return ControlsGroupMainFrameStyle;
}
}
And then you can set the style : ControlsGroupMainFrame4.Style = MyStyles.GetControlsGroupMainFrameStyle();
Also, it's not clear how you set the Static Style in XAML. You can see Style apps using XAML - .NET MAUI | Microsoft Learn
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.