XAML 如何使复选框圆形

xmq68pz9  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(126)

我在毛伊岛遇到了一些单选按钮的问题:
https://github.com/dotnet/maui/issues/11418
https://github.com/dotnet/maui/issues/7595
所以我决定用一组复选框来代替,我需要让复选框看起来像单选按钮,我的意思是让它变圆。我在网上找不到任何简单的解决办法。

sy5wg1nm

sy5wg1nm1#

您可以使用.NET MAUI处理程序来设置CheckBox的角半径。看看下面的例子:
1.创建一个新控件,其子类为CheckBox:

public class MyRoundedCornerCheckBox : CheckBox
{
}

2.在xaml中进行比较,

<local:MyRoundedCornerCheckBox />

3.在后面的代码中,您可以使用处理程序来修改复选框,

public MainPage()
    {
        InitializeComponent();
        ModifyCheckBox();

    }

    public void ModifyCheckBox()
    {
        Microsoft.Maui.Handlers.CheckBoxHandler.Mapper.AppendToMapping("MyCustomization", (handler, view) =>
        {
            if (view is MyRoundedCornerCheckBox)
            {

#if WINDOWS
                handler.PlatformView.CornerRadius = new Microsoft.UI.Xaml.CornerRadius(20);
#endif
            }          
        });
    }

有关更多信息,请参阅Customize controls with handlers.
希望能帮上忙!

相关问题