2016-09-21 13 views
1

Windows 10ユーザーがダーク/ライトテーマを使用している場合、TextBlockのテキストを設定します。私は試しましたWindows 10でダークテーマ(UWP)を使用する場合のTextBlockテキストの設定

RequestedTheme == ElementTheme.Dark 

しかし、動作しません。

EDIT: 私はあなたが試すことができ、この

if(user uses dark them) 
{ 
    mTextBlock.Text = "Dark" 
} 
elseif(user uses light theme) 
{ 
    mTextBlock.Text = "Light" 
} 
+0

あなたはライト/ダークにまたはとしてのTextBlockのテキストを設定しますかこの質問の答えは? – AVK

+0

@AVKNaiduはいたとえば –

+0

テキストをテキストブロックに設定する方法に関する完全なコードを表示できますか? – AVK

答えて

1

ApplicationThemeEnumです。以下のようにチェックすることができます。

if (Application.Current.RequestedTheme == ApplicationTheme.Dark) 
{ 
    mTextBlock.Text = "Dark" 
} 
elseif(Application.Current.RequestedTheme == ApplicationTheme.Light) 
{ 
    mTextBlock.Text = "Light" 
} 

詳細情報Here

+0

それは動作しません。 TextBlockには常に「ライト」が表示されます –

+0

更新日時が更新されている場合、ダークが実装されていないため、常に明るくなります。また、テーマについてはapp.xamlをチェックしてください。 Defaultの代わりにLightに設定している可能性があります。 – AVK

+0

私の欠点は、RequestedThemeをLightに設定したことでした。私はそれを削除する場合、コードは期待どおりに動作します。ありがとうございました –

0

ようにそれを設定したい:あなたはあなたのアプリケーションに課されているもののテーマをチェックするために

Application.Current.Resources["SystemAccentColor"] 
+0

[リソースキー](https://msdn.microsoft.com/en-us/windows/uwp/controls-and-patterns/xaml-theme-resources#light-and-dark-theme-colors)のように指定するだけです+1 –

+0

アクセントの色と明/暗のモードは、2つの完全に別個の設定です。アクセントの色は、システムが明るいモードであるか暗いモードであるかについては何も知らない。 – BoltClock

0

あなたが何をしたい達成するために、{ThemeResource}マークアップ拡張機能を使用することができます。あなたのPage.xamlをで :

<Page.Resources> 
    <ResourceDictionary> 
     <ResourceDictionary.ThemeDictionaries>     
      <ResourceDictionary Source="Dictionary2.xaml" x:Key="Dark"/> 
      <ResourceDictionary Source="Dictionary1.xaml" x:Key="Light"/> 
     </ResourceDictionary.ThemeDictionaries> 
    </ResourceDictionary> 
</Page.Resources> 
<StackPanel> 
    <TextBlock Text="{ThemeResource txt}"/> 
</StackPanel> 

Dictionary1.xaml:

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:Styles"> 

<x:String x:Key="txt">Light</x:String> 

</ResourceDictionary> 

Dictionary2.xaml:

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:Styles"> 

<x:String x:Key="txt">Dark</x:String> 

</ResourceDictionary> 
関連する問題