我正在做一个 Windows 8 应用程序(METRO UI / XAML / C#),我在设置栏中有一个切换开关。我希望此开关能够实时在“浅色”和“深色”主题之间进行选择。我已经在我的 StandardStyles.xaml 上制作了主题:
<!-- LIGHT THEME -->
<Style x:Key="LightTheme" TargetType="Panel">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush>
<GradientStop Color="#cdeae5" Offset="0"/>
<GradientStop Color="#c0dabd" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="ChildrenTransitions">
<Setter.Value>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Setter.Value>
</Setter>
</Style>
<!-- DARK THEME -->
<Style x:Key="DarkTheme" TargetType="Panel">
<Setter Property="Background">
<Setter.Value>
<LinearGradientBrush>
<GradientStop Color="#fea569" Offset="0"/>
<GradientStop Color="#f63f3b" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
<Setter Property="ChildrenTransitions">
<Setter.Value>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Setter.Value>
</Setter>
</Style>
如何使用拨动开关实时选择它们?我认为它会是这样的:
private void ThemeSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (ThemeSwitch.IsOn)
{
// LIGHT THEME
// TEXT SHOWING "Light Theme"
}
else
{
// DARK THEME
// TEXT SHOWING "Dark Theme"
}
}
但这是我能走的最远。
提前致谢。这是我第一次使用 C# 和 XAML 进行编程。