C# 在Windows Phone 8应用程序中为文本添加字体颜色
我正在尝试使用以下代码更改Windows Phone 8应用程序中文本的字体颜色C# 在Windows Phone 8应用程序中为文本添加字体颜色,c#,windows-phone-8,C#,Windows Phone 8,我正在尝试使用以下代码更改Windows Phone 8应用程序中文本的字体颜色 RootFrame.Foreground = new SolidColorBrush(Colors.Purple); 这并没有给我任何字体颜色的变化。我正在App.xaml.cs构造函数中添加这一行 如果我以类似的方式更改背景色,它就会工作。有人能解释一下这有什么问题吗?在XAML中使用name属性为文本框设置name YourTextBoxName.Foreground = new SolidColorBrus
RootFrame.Foreground = new SolidColorBrush(Colors.Purple);
这并没有给我任何字体颜色的变化。我正在App.xaml.cs构造函数中添加这一行
如果我以类似的方式更改背景色,它就会工作。有人能解释一下这有什么问题吗?在XAML中使用name属性为文本框设置name
YourTextBoxName.Foreground = new SolidColorBrush(Colors.Red);
<TextBox Name="textBox1"....>
在整个应用程序中设置文本的字体颜色,而不是为每个控件单独设置字体颜色,这对我来说很有用
(App.Current.Resources["PhoneForegroundBrush"] as SolidColorBrush).Color = Colors.Purple;
在应用程序资源中创建样式,然后可以使用代码添加样式 创建应用程序资源:
<Application.Resources>
<Style TargetType="TextBox" x:Key="MyTextBox">
<Setter Property="Width" Value="90" />
<Setter Property="Background" Value="Azure"></Setter>
<Setter Property="Foreground" Value="Purple"></Setter>
</Style>
</Application.Resources>
这是有效的。如果我想更改整个应用程序,但不想使用模板,该怎么办?您无法应用。您必须选择样式或这样做更改rootframe的前景不会更改其中所有文本控件的前景。您必须单独设置它们。但是背景颜色正在更改?
<Application.Resources>
<Style TargetType="TextBox" x:Key="MyTextBox">
<Setter Property="Width" Value="90" />
<Setter Property="Background" Value="Azure"></Setter>
<Setter Property="Foreground" Value="Purple"></Setter>
</Style>
</Application.Resources>
YourTextBoxName.Style = Application.Current.Resources["MyTextBox"] as Style;