窗口电话8.1:更改按钮的背景颜色
-
02-01-2020 - |
题
我正在研究开发窗口电话8.1的应用程序。当我尝试更改按钮的背景颜色时,我遇到了问题。在mainPage.xaml中,我有以下代码:
<Button
Name="button" Background="Pink"
Click="OnClick">
ClickMe1
</Button>
.
然后我定义onclick事件:`
private void ClickMe_Click(object sender, RoutedEventArgs e)
{
button.Background = new SolidColorBrush(Colors.Green);
}
.
但它不起作用,因为:名称“颜色”在当前的上下文中不会出现 我试图修复
void OnClick(object sender, RoutedEventArgs e)
{
button.Background = Brushes.Green;
}
.
但它不起作用:(
解决方案
在Windows Phone 8.1中,颜色类是 windows.ui 命名空间。
所以你可以设置这样的按钮背景:
button.Background = new SolidColorBrush(Windows.UI.Colors.Red);
. 不隶属于 StackOverflow