c# - How do I set a frame border color to change with the app theme? - Stack Overflow

I had no issues creating a frame in C# markup and it's been displaying just fine before now.I tri

I had no issues creating a frame in C# markup and it's been displaying just fine before now.

I tried to set the BorderColor property to dynamically change with the app theme using frame.SetAppThemeColor(Frame.BorderColor, Colors.White, Colors.Black).

    public class ExampleFrame : ContentView
    {
        public ExampleFrame()
        {

            Frame frame = new Frame
            {
                BackgroundColor = Colors.Transparent,
                CornerRadius = 0,
                Margin = 0
            };

            frame.SetAppThemeColor(Frame.BorderColor, Colors.LightGray, Colors.White);

            Content = frame;
        }
    }

This gives me the following error under Frame.BorderColor:

'Rect' does not contain a definition for 'BorderColor' and no accessible extension method 'BorderColor' accepting a first argument of type 'Rect' could be found (are you missing a using directive or an assembly reference?)

I assume I have the wrong property but I'm not sure what the right one would be since BorderBrush also produces the same error.

I had no issues creating a frame in C# markup and it's been displaying just fine before now.

I tried to set the BorderColor property to dynamically change with the app theme using frame.SetAppThemeColor(Frame.BorderColor, Colors.White, Colors.Black).

    public class ExampleFrame : ContentView
    {
        public ExampleFrame()
        {

            Frame frame = new Frame
            {
                BackgroundColor = Colors.Transparent,
                CornerRadius = 0,
                Margin = 0
            };

            frame.SetAppThemeColor(Frame.BorderColor, Colors.LightGray, Colors.White);

            Content = frame;
        }
    }

This gives me the following error under Frame.BorderColor:

'Rect' does not contain a definition for 'BorderColor' and no accessible extension method 'BorderColor' accepting a first argument of type 'Rect' could be found (are you missing a using directive or an assembly reference?)

I assume I have the wrong property but I'm not sure what the right one would be since BorderBrush also produces the same error.

Share asked Nov 22, 2024 at 6:43 Wrinkly-ButtsWrinkly-Butts 134 bronze badges 3
  • Frame.BorderColorProperty not Frame.BorderColor. – Stephen Quan Commented Nov 22, 2024 at 8:22
  • 2 Do not use frame. – H.A.H. Commented Nov 22, 2024 at 9:18
  • @H.A.H. is right. Frame docs says: The Frame control is marked as obsolete in .NET MAUI 9, and will be completely removed in a future release. The Border control should be used in its place. For more information see Border. – Stephen Quan Commented Nov 22, 2024 at 10:20
Add a comment  | 

1 Answer 1

Reset to default 0

Please change the following code:

frame.SetAppThemeColor(Frame.BorderColor, Colors.LightGray, Colors.White);

to

frame.SetAppThemeColor(Microsoft.Maui.Controls.Frame.BorderColorProperty, Colors.LightGray, Colors.White);

In addition, the official document about the Frame in the maui 8.0 said:

The Frame class existed in Xamarin.Forms and is present in .NET MAUI for users who are migrating their apps from Xamarin.Forms to .NET MAUI. If you're building a new .NET MAUI app it's recommended to use Border instead, and to set shadows using the Shadow bindable property on VisualElement.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742293732a4416695.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信