Windows phone Xamarin在UWP中形成开关文本

Windows phone Xamarin在UWP中形成开关文本,windows-phone,xamarin-forms,uwp,c#,xamarin.forms,Windows Phone,Xamarin Forms,Uwp,C#,Xamarin.forms,就像其他人遇到的一样,我希望在中更改开关控件旁边的文本,这似乎只适用于Android的ootb。不同之处在于,我希望在中更改控件的文本(自从前一个人提出问题以来,已经过去了一年多) 是否有人对此有(相对容易的)解决方案,或者仍然是最好的解决方案 有人对此有(相对容易的)解决方案吗 我检查了Xamarin.forms开关源代码,对于WinRT平台,开关控件的样式实际上遵循了Windows.UI.Xaml.Controls.ToggleSwitch的样式 因此,我们可以根据需要创建和修改默认模板 有

就像其他人遇到的一样,我希望在中更改
开关
控件旁边的文本,这似乎只适用于Android的ootb。不同之处在于,我希望在中更改控件的文本(自从前一个人提出问题以来,已经过去了一年多)

是否有人对此有(相对容易的)解决方案,或者仍然是最好的解决方案

有人对此有(相对容易的)解决方案吗

我检查了Xamarin.forms开关源代码,对于WinRT平台,开关控件的样式实际上遵循了
Windows.UI.Xaml.Controls.ToggleSwitch
的样式

因此,我们可以根据需要创建和修改默认模板

有关默认的
ToggleSwitch
样式和模板,请参见

请注意这一部分:

<ContentPresenter x:Name="OffContentPresenter"
                        Grid.Row="1"
                        Grid.RowSpan="3"
                        Grid.Column="2"
                        Opacity="0"
                        Foreground="{TemplateBinding Foreground}"
                        IsHitTestVisible="False"
                        Content="{TemplateBinding OffContent}"
                        ContentTemplate="{TemplateBinding OffContentTemplate}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        AutomationProperties.AccessibilityView="Raw" />
    <ContentPresenter x:Name="OnContentPresenter"
                        Grid.Row="1"
                        Grid.RowSpan="3"
                        Grid.Column="2"
                        Opacity="0"
                        Foreground="{TemplateBinding Foreground}"
                        IsHitTestVisible="False"
                        Content="{TemplateBinding OnContent}"
                        ContentTemplate="{TemplateBinding OnContentTemplate}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        AutomationProperties.AccessibilityView="Raw" />
  • 修改模板:

    <ContentPresenter x:Name="OffContentPresenter"
                        Grid.Row="1"
                        Grid.RowSpan="3"
                        Grid.Column="2"
                        Opacity="0"
                        Foreground="{TemplateBinding Foreground}"
                        IsHitTestVisible="False"
                        Content="{StaticResource MyOffContent}"
                        ContentTemplate="{TemplateBinding OffContentTemplate}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        AutomationProperties.AccessibilityView="Raw" />
        <ContentPresenter x:Name="OnContentPresenter"
                        Grid.Row="1"
                        Grid.RowSpan="3"
                        Grid.Column="2"
                        Opacity="0"
                        Foreground="{TemplateBinding Foreground}"
                        IsHitTestVisible="False"
                        Content="{StaticResource MyOnContent}"
                        ContentTemplate="{TemplateBinding OnContentTemplate}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        AutomationProperties.AccessibilityView="Raw" />
    
    
    
  • 示例XAML代码:

    屏幕截图:

    有人对此有(相对容易的)解决方案吗

    我检查了Xamarin.forms开关源代码,对于WinRT平台,开关控件的样式实际上遵循了
    Windows.UI.Xaml.Controls.ToggleSwitch
    的样式

    因此,我们可以根据需要创建和修改默认模板

    有关默认的
    ToggleSwitch
    样式和模板,请参见

    请注意这一部分:

    <ContentPresenter x:Name="OffContentPresenter"
                            Grid.Row="1"
                            Grid.RowSpan="3"
                            Grid.Column="2"
                            Opacity="0"
                            Foreground="{TemplateBinding Foreground}"
                            IsHitTestVisible="False"
                            Content="{TemplateBinding OffContent}"
                            ContentTemplate="{TemplateBinding OffContentTemplate}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            AutomationProperties.AccessibilityView="Raw" />
        <ContentPresenter x:Name="OnContentPresenter"
                            Grid.Row="1"
                            Grid.RowSpan="3"
                            Grid.Column="2"
                            Opacity="0"
                            Foreground="{TemplateBinding Foreground}"
                            IsHitTestVisible="False"
                            Content="{TemplateBinding OnContent}"
                            ContentTemplate="{TemplateBinding OnContentTemplate}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            AutomationProperties.AccessibilityView="Raw" />
    
  • 修改模板:

    <ContentPresenter x:Name="OffContentPresenter"
                        Grid.Row="1"
                        Grid.RowSpan="3"
                        Grid.Column="2"
                        Opacity="0"
                        Foreground="{TemplateBinding Foreground}"
                        IsHitTestVisible="False"
                        Content="{StaticResource MyOffContent}"
                        ContentTemplate="{TemplateBinding OffContentTemplate}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        AutomationProperties.AccessibilityView="Raw" />
        <ContentPresenter x:Name="OnContentPresenter"
                        Grid.Row="1"
                        Grid.RowSpan="3"
                        Grid.Column="2"
                        Opacity="0"
                        Foreground="{TemplateBinding Foreground}"
                        IsHitTestVisible="False"
                        Content="{StaticResource MyOnContent}"
                        ContentTemplate="{TemplateBinding OnContentTemplate}"
                        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                        AutomationProperties.AccessibilityView="Raw" />
    
    
    
  • 示例XAML代码:

    屏幕截图:


    codeplaste
    链接已过期。您能将示例xaml粘贴到答案中吗?
    code粘贴
    链接已过期。你能在答案中粘贴样本xaml吗?