我想,这是一个错误。
要重现,请在Windows Phone上以黑暗主题启动应用程序。 启动应用程序后,将主题更改为浅。 然后点击"启用"按钮。 你会看到" 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;
}
答案 0 :(得分:1)
我找到的唯一解决方案是从generic.xaml获取Button样式并将Storyboard添加到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>
答案 1 :(得分:0)
使用Visual Studio Blend将样式设置为按钮。