You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UraniumUI RadioButton标签位置反转样式不符官方示例求助

UraniumUI RadioButton LabelPosition="Before" 样式不生效问题

我参照UraniumUI官方文档实现标签位置反转的RadioButton,设置LabelPosition="Before"后,实际显示效果与预期完全不符。

预期效果

示例效果

实际效果

实际效果

主页面XAML代码

<?xml version="1.0" encoding="utf-8" ?>
<uranium:UraniumContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" 
                            xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                            x:Class="MAUIUraniumTest.MainPage" 
                            xmlns:uranium="http://schemas.enisn-projects.io/dotnet/maui/uraniumui" 
                            xmlns:material="http://schemas.enisn-projects.io/dotnet/maui/uraniumui/material">
    <StackLayout Margin="20">
        <material:RadioButtonGroupView>
            <material:RadioButton Text="Option 1" LabelPosition="Before" />
            <material:RadioButton Text="Option 2" LabelPosition="Before" />
            <material:RadioButton Text="Option 3 (Disabled)" IsDisabled="True" LabelPosition="Before" />
            <material:RadioButton Text="Option 4 (Disabled)" IsDisabled="True" IsChecked="True" LabelPosition="Before" />
        </material:RadioButtonGroupView>
    </StackLayout>
</uranium:UraniumContentPage>

后台代码

public partial class MainPage : UraniumContentPage
{
    int count = 0;
    public MainPage()
    {
        InitializeComponent();
    }
}

App.xaml代码

<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui" 
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
             xmlns:local="clr-namespace:MAUIUraniumTest" 
             xmlns:material="http://schemas.enisn-projects.io/dotnet/maui/uraniumui/material" 
             x:Class="MAUIUraniumTest.App">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary x:Name="appColors" Source="Resources/Styles/Colors.xaml" />
                <ResourceDictionary x:Name="appStyles" Source="Resources/Styles/Styles.xaml" />
                <material:StyleResource ColorsOverride="{x:Reference appColors}" BasedOn="{x:Reference appStyles}" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

MauiProgram.cs代码

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .UseUraniumUI()
            .UseUraniumUIMaterial()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
            });
#if DEBUG
        builder.Logging.AddDebug();
#endif
        return builder.Build();
    }
}

程序可正常编译运行,操作均遵循官方文档,求解决样式不符的问题。


解决建议

  1. 更新UraniumUI版本:确认UraniumUI.Material NuGet包是最新版本,旧版本可能存在LabelPosition属性的实现问题,通过NuGet包管理器更新到最新版。
  2. 调整资源合并顺序:检查App.xaml中资源字典的合并顺序,确保UraniumUI的StyleResource在项目自有资源之后加载,避免自定义样式覆盖UraniumUI的内置样式。
  3. 显式指定RadioButton样式:为每个material:RadioButton添加UraniumUI的内置样式引用,强制使用框架样式:
    <material:RadioButton Text="Option 1" LabelPosition="Before" Style="{StaticResource MaterialRadioButtonStyle}" />
    
  4. 清理重建项目:清理项目的bin/obj目录,然后重新编译运行,避免缓存导致的样式不生效问题。
  5. 检查平台适配:如果问题仅出现在特定平台(如Android/iOS),查看UraniumUI的平台文档,确认是否需要额外的平台配置。

内容的提问来源于stack exchange,提问作者Aveyron2033

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 11:24:53