我在 .Net Maui 有一个开关控件:
<Switch IsToggled="true" Grid.Row="3" Grid.Column="1" VerticalOptions="Center"/>
Run Code Online (Sandbox Code Playgroud)
默认情况下,它根据其状态显示“开/关”标签。我希望它什么也不显示。
有什么方法可以隐藏/删除它吗?
不幸的是,毛伊岛开关控件将SwitchOnVisualState \ SwitchOffVisualState内容设置为常量字符串,并且您显然还无法覆盖它。
不过,您可以通过 App.xaml 文件覆盖 WinUI 中的 ToggleSwitch 类样式。
项目\Platforms\Windows\App.xaml
它应该看起来像这样。
<maui:MauiWinUIApplication
x:Class="Project.Client.WinUI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:maui="using:Microsoft.Maui"
xmlns:local="using:Project.Client.WinUI">
<maui:MauiWinUIApplication.Resources>
<ResourceDictionary>
<!-- ToggleSwitch : Turn off ON/OFF label -->
<Style TargetType="ToggleSwitch">
<Setter Property="OffContent" Value=" " />
<Setter Property="OnContent" Value=" " />
<Setter Property="Margin" Value="0,0,-110,0" />
</Style>
</ResourceDictionary>
</maui:MauiWinUIApplication.Resources>
</maui:MauiWinUIApplication>
Run Code Online (Sandbox Code Playgroud)
看?
| 归档时间: |
|
| 查看次数: |
3667 次 |
| 最近记录: |