2016-09-13 19 views
1

hereと遭遇したのと同じように、Switchのコントロールの横のテキストをに変更すると、Android用の可能性があるようです。違いは、コントロールのテキストをに変更しようとしていることです(前の人が質問してから1年以上経過しています)。XamarinフォームのテキストをUWPで

誰にもこれに対応する(比較的簡単な)ソリューションがありますか、またはthis answerは依然として最良のソリューションですか?

答えて

4

誰もが、私はXamarin.formsは、ソースコードを切り替えて確認し、この

ための(比較的容易な)解決策を持っています、WinRTのプラットフォームのために、スイッチコントロールのスタイルは、実際にWindows.UI.Xaml.Controls.ToggleSwitchのスタイルに従っています。

私たちは私たちの要件に基づいてデフォルトテンプレートを変更することができます。デフォルトToggleSwitchスタイルやテンプレートの場合

は、here

を参照してください。この部分を注意してください:

<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" /> 

我々は親指を切り替えるに次のテキストを変更する必要がある場合は、我々だけでContentプロパティを設定しないようにすることができますTemplateBindingを使用してください。

  1. Application.Resourcesノード(App.xaml)の下にデフォルトのスタイルを追加します。

    <x:String x:Key="MyOffContent">Close</x:String> 
    <x:String x:Key="MyOnContent">Open</x:String> 
    
  2. 変更テンプレート:

    <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" /> 
    

をあなたはこれで慣れていない場合は、ResourceDictionary and XAML resource references

  • はあなたが必要な場合は、背後にあるコードから値を変更し、2つのリソースの作成を参照してくださいサンプルXAMLコード:http://codepaste.net/qjin7c

    スクリーンショット:

    enter image description here

  • +0

    'CodePaste'リンクの有効期限が切れています。回答にサンプルxamlを貼り付けることはできますか? – user1

    関連する問題