2015-09-27 55 views
1

我想,這是一個錯誤。主題變更不會影響Windows Phone 8.1上禁用的控制主題

要重現,請在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

你檢查按鈕的控件模板來看看它的設計不當? – WiredPrairie

+0

按鈕的控件模板是默認的 – Dmitry

+0

我試圖將按鈕的RequestedTemplate更改爲Light。但它無法幫助。 – Dmitry

回答

1

我發現的唯一的解決方案是從generic.xaml獲得按鈕的風格和故事板添加到正常的視覺狀態是這樣的:

<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> 
0

使用Visual Studio混合組樣式的按鈕。

+0

我同意,這看起來像是決定,但在這種情況下,設置模板到按鈕是不可取的設計。 – Dmitry