如何从Xamarin表单中的开关中删除开/关文本

Moh*_*had 4 c# xamarin uwp

如何从开关中删除开/关文本

<Label Text="Below is the binded data: "></Label>
<Label Text="{Binding MyData}"></Label>
<Label x:Name="lbldisp"></Label>
<Switch Toggled="SwitchToggled"></Switch>
Run Code Online (Sandbox Code Playgroud)

W0R*_*RT4 8

如何从开关中删除开/关文本

SwitchUWP中的相对应的本机控件为ToggleSwitch。如果要删除on/off内容,可以ToggleSwitch直接在UWP项目中创建没有文本样式的内容,如下所示:

应用程式

<Application.Resources>
    <Style TargetType="ToggleSwitch">
        <Setter Property="OffContent" Value=" " />
        <Setter Property="OnContent" Value=" " />
        <Setter Property="Margin" Value="0,0,-110,0" /> 
    </Style>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

![在此处输入图片描述

  • 这可行,但是如果您错过了它,则需要将其添加到UWP项目中的App.xaml中,而不是共享项目中。但是,至少在我的情况下,与“开/关”字符串的长度相比,开关的“内容”部分现在是一个巨大的空白。.h还没有完全解决这个问题。 (3认同)