小编mga*_*ant的帖子

覆盖主题画笔Windows 10 UWP

我试图在Windows 10中覆盖一些样式颜色,但我无法让它工作.

我的app.xaml看起来像这样:

        <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Resources.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default" Source="Theme.xaml"/>
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

我的Theme.xaml看起来像这样

<ResourceDictionary
x:Key="Default"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<SolidColorBrush x:Key="ListBoxBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxFocusBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemPressedBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemSelectedForegroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ListBoxItemSelectedBackgroundThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="FocusVisualBlackStrokeThemeBrush" Color="Transparent" />
<SolidColorBrush x:Key="ScrollBarButtonForegroundThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ScrollBarPanningBackgroundThemeBrush" Color="Red" />
<SolidColorBrush x:Key="ButtonPressedBackgroundThemeBrush" Color="White"/>

<SolidColorBrush x:Key="SearchBoxHitHighlightSelectedForegroundThemeBrush" Color="Red"/>
<SolidColorBrush x:Key="SearchBoxHitHighlightForegroundThemeBrush" Color="Pink"/>
Run Code Online (Sandbox Code Playgroud)

但它不起作用,它不会覆盖任何地方的样式.

xaml windows-phone win-universal-app windows-10

11
推荐指数
1
解决办法
6335
查看次数

枚举值的GetCustomAttributes返回一个空数组

我正在努力将Windows 8.1通用应用程序升级到Windows 10 UWP应用程序.在我的Windows 10 UWP应用程序中,有一部分代码在之前完全无法正常工作.

我有一个看起来像这样的枚举:

public enum EStaticFile
{
    [StringValue("Path of a file")]
    CONFIG_FILE_1,    

    [StringValue("Path of a file")]
    CONFIG_FILE_2
}
Run Code Online (Sandbox Code Playgroud)

当我尝试获取任何枚举值的属性时,它总是返回一个空数组.我使用以下代码:

public static StringValue GetStringValueAttribute(this Enum aEnumValue)
{
    Type type = aEnumValue.GetType();

    FieldInfo fieldInfo = type.GetRuntimeField(aEnumValue.ToString());
    StringValue[] attributes = fieldInfo.GetCustomAttributes(typeof(StringValue), false) as StringValue[];
    if (attributes.Length > 0)
    {
        return attributes[0];
    }

   return null;
}
Run Code Online (Sandbox Code Playgroud)

GetCustomAttributes总是返回一个空数组,所以attributes.Length总是0,所以函数返回null;

在Windows 10中有什么变化阻止它工作?

非常感谢!

c# enums custom-attributes win-universal-app windows-10

5
推荐指数
1
解决办法
645
查看次数