Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UWP应用程序中的自定义主题_C#_Themes_Uwp - Fatal编程技术网

C# UWP应用程序中的自定义主题

C# UWP应用程序中的自定义主题,c#,themes,uwp,C#,Themes,Uwp,我正在开发一个UWP应用程序,其中我希望从一个文件(包含颜色代码)动态设置主题 我创建的文件是一个XML文件,其节点包含映射到应用程序控件的颜色代码 用户可以更新提供的XML文件中的颜色代码,这应该反映应用程序中的主题更改 我可以为该文件设置任何自定义位置,以便用户可以编辑该文件的内容吗 这是在UWP应用程序中实现主题的正确方法吗 另外,我对超宽带技术很新 提前感谢。默认情况下,UWP应用程序支持两个主题—亮和暗 您可以在app.xaml中指定应用程序的主题,方法是将RequestedTheme

我正在开发一个UWP应用程序,其中我希望从一个文件(包含颜色代码)动态设置主题

我创建的文件是一个XML文件,其节点包含映射到应用程序控件的颜色代码

用户可以更新提供的XML文件中的颜色代码,这应该反映应用程序中的主题更改

我可以为该文件设置任何自定义位置,以便用户可以编辑该文件的内容吗

这是在UWP应用程序中实现主题的正确方法吗

另外,我对超宽带技术很新


提前感谢。

默认情况下,UWP应用程序支持两个主题—

您可以在
app.xaml
中指定应用程序的主题,方法是将
RequestedTheme
属性设置为其中一个值(默认设置为
Light
),或在
app.xaml.cs
中使用
RequestedTheme=ApplicationTheme.Light(稍后在任何位置更改它将导致引发异常)

如果您没有设置
RequestedTheme
属性,它将在任何运行周年更新和更新版本的W10移动设备或W10 PC上反映
Settings>Personalization>Colors
中设置的主题。在较旧的Windows 10桌面版本上,它将是

您还可以设置任何特定
FrameworkElement
的主题,该元素默认设置为
ElementTheme.Default
,以便从其父元素继承主题

<StackPanel RequestedTheme="Light">
   <TextBlock>Text using light theme.</TextBlock>
   <TextBlock RequestedTheme="Dark">Text using dark theme.</TextBlock>
</StackPanel>
或者您可以使用
SystemControlBackgroundAccentBrush
,它将反映在“设置”应用程序中选择的重音颜色

您还可以编写自己的
主题词典
,为每个主题指定颜色。下面是一个简单主题词典的示例:

<ResourceDictionary.ThemeDictionaries>
    <ResourceDictionary x:Key="Light">
        <SolidColorBrush x:Key="MyButtonBackgroundThemeBrush" Color="White"/
        <SolidColorBrush x:Key="MyButtonForegroundThemeBrush" Color="Black"/>
    </ResourceDictionary>
    <ResourceDictionary x:Key="Dark">
        <SolidColorBrush x:Key="MyButtonBackgroundThemeBrush" Color="Black"/>
        <SolidColorBrush x:Key="MyButtonForegroundThemeBrush" Color="White"/>
    </ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

<ResourceDictionary.ThemeDictionaries>
    <ResourceDictionary x:Key="Light">
        <SolidColorBrush x:Key="MyButtonBackgroundThemeBrush" Color="White"/
        <SolidColorBrush x:Key="MyButtonForegroundThemeBrush" Color="Black"/>
    </ResourceDictionary>
    <ResourceDictionary x:Key="Dark">
        <SolidColorBrush x:Key="MyButtonBackgroundThemeBrush" Color="Black"/>
        <SolidColorBrush x:Key="MyButtonForegroundThemeBrush" Color="White"/>
    </ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<Button Content="Themed button"
        Background="{ThemeResource MyButtonBackgroundThemeBrush}"
        Foreground="{ThemeResource MyButtonForegroundThemeBrush}"/
        />