更改主题不会影响Windows Phone 8.1上已禁用的控制主题
本文关键字:控制 Phone 影响 Windows | 更新日期: 2023-09-27 18:14:48
我想,这是一个bug。
要复制,在Windows Phone上启动深色主题的应用程序。应用程序启动后,将主题更改为light。然后点击"启用"按钮。您将看到"样本"按钮消失。因为它的主题仍然是黑暗。
<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;
}
我找到的唯一解决方案是从通用中获得按钮样式。并在Normal视觉状态中添加storyboard,如下所示:
<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>
使用Visual studio Blend为按钮设置样式