主题更改不会影响 Windows Phone 8.1 上禁用的控件主题

Theme changing doesn't influence disabled control theme on Windows Phone 8.1

我想,这是一个错误。

要重现,请在 Windows Phone 上以深色主题启动应用程序。 启动应用程序后,将主题更改为浅色。 然后点击 "Enable" 按钮。 您会看到 "Sample" 按钮消失。因为它的主题仍然是黑暗的。

<Page x:Class="ButtonThemeTest.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
      mc:Ignorable="d">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Button x:Name="ButtonTest"
                Content="Sample"
                IsEnabled="False" />
        <Button Grid.Row="1"
                Click="ButtonBase_OnClick"
                Content="Enable" />
        <Button Grid.Row="2"
                Click="ButtonBase_OnClick2"
                Content="Disable" />
    </Grid>
</Page>

后面的代码:

private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
    ButtonTest.IsEnabled = true;
}

private void ButtonBase_OnClick2(object sender, RoutedEventArgs e)
{
    ButtonTest.IsEnabled = false;
}

使用 Visual studio 混合按钮设置样式。

我找到的唯一解决方案是从 generic.xaml 获取 Button 样式并将故事板添加到 Normal 视觉状态,如下所示:

<Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentPresenter"
                                   Storyboard.TargetProperty="Foreground">
        <DiscreteObjectKeyFrame KeyTime="0"
                                Value="{ThemeResource PhoneForegroundBrush}" />
    </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                   Storyboard.TargetProperty="BorderBrush">
        <DiscreteObjectKeyFrame KeyTime="0"
                                Value="{ThemeResource PhoneForegroundBrush}" />
    </ObjectAnimationUsingKeyFrames>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Border"
                                   Storyboard.TargetProperty="Background">
        <DiscreteObjectKeyFrame KeyTime="0"
                                Value="{ThemeResource PhoneBackgroundBrush}" />
    </ObjectAnimationUsingKeyFrames>
</Storyboard>