我尝试从开关中删除文本但我不能,开关代码是:
<Switch x:Name="styleSwitch"
HorizontalOptions="Center"
Scale="1.3"/>
风格是:
<Style TargetType="Switch">
<Setter Property="OnColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource White}}" />
<Setter Property="ThumbColor" Value="{StaticResource White}" />
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Disabled">
<VisualState.Setters>
<Setter Property="OnColor" Value="{AppThemeBinding Light={StaticResource Gray300}, Dark={StaticResource Gray600}}" />
<Setter Property="ThumbColor" Value="{AppThemeBinding Light={StaticResource Gray300}, Dark={StaticResource Gray600}}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="On">
<VisualState.Setters>
<Setter Property="OnColor" Value="{AppThemeBinding Light={StaticResource Secondary}, Dark={StaticResource Gray200}}" />
<Setter Property="ThumbColor" Value="{AppThemeBinding Light={StaticResource Primary}, Dark={StaticResource White}}" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Off">
<VisualState.Setters>
<Setter Property="ThumbColor" Value="{AppThemeBinding Light={StaticResource Gray400}, Dark={StaticResource Gray500}}" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
但是在 Switch 右边出现了一个文本,我不知道如何删除它:
这是 Maui 的默认项目,所以我不知道该文本来自何处,我试图找到它并删除它,但我做不到。
我还尝试添加一个标签并绑定(bind)到该开关,如 documentation ,但这不起作用,只需添加一个新标签即可。
我该怎么做?
编辑 刚刚出现在Windows中
编辑 2
我把步骤重现我的问题:
首先创建一个新的 Maui 项目:
在xaml MainPage中添加:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="SwitchWithText.MainPage">
<ScrollView>
<VerticalStackLayout
Spacing="25"
Padding="30,0"
VerticalOptions="Center">
<Switch></Switch>
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dot net bot waving hi to you!"
HeightRequest="200"
HorizontalOptions="Center" />
<Label
Text="Hello, World!"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="Center" />
<Label
Text="Welcome to .NET Multi-platform App UI"
SemanticProperties.HeadingLevel="Level2"
SemanticProperties.Description="Welcome to dot net Multi platform App U I"
FontSize="18"
HorizontalOptions="Center" />
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ScrollView>
</ContentPage>
只要在 Windows 机器上运行,应用程序显示如下:
如果您在 Android 上运行它,该文本不会出现,只会出现在 Windows 桌面上,我在 Xamarin 中看到您可以使用 ContentOff=""
或 ContentOn=""删除它
但在 MAUI 中你不能,我不知道我是否需要图书馆或什么,我阅读了所有相关文档,但我什么也没看到。
最佳答案
是的,这是毛伊岛 swich 的一个已知问题。
你可以在这里跟进这个问题:https://github.com/dotnet/maui/issues/6177 .
感谢您对此问题的反馈。
祝你有美好的一天。
https://stackoverflow.com/questions/72908823/