1.Content属性及字体相关的属性
class="brush:csharp;collapse:true;;gutter:true;">using System; using System.Windows; using System.Windows.Media; namespace LY.DisplaySomeText { public class DisplaySomeText:Window { Brush brush = new LinearGradientBrush(Colors.Black, Colors.White, new Point(0, 0), new Point(1, 1)); [STAThread] public static void Main() { new Application().Run(new DisplaySomeText()); } public DisplaySomeText() { Title = "Display Some Text"; //Content = "Content can be simple text!"; //Content = System.EventArgs.Empty; Content = DateTime.Now; //设置字体系列 FontFamily = new FontFamily("宋体"); FontSize = 48; FontStyle = FontStyles.Italic; FontWeight = FontWeights.Bold; //Background = brush; Foreground = brush; //将窗口大小调整为适应内容的大小 SizeToContent = SizeToContent.WidthAndHeight; //设置边框的画刷 BorderBrush = Brushes.Red; //设置上下左右边框的宽度 BorderThickness = new Thickness(25, 50, 75, 100); } } }
1)没有Font类,需通过FontFamily(字体系列),FontSize、FontStyle、FontWeight等属性来设置。
using System; using System.Windows; using System.Windows.Media; using System.Windows.Input; namespace LY.RecordKeyStrokes { public class RecordKeyStrokes:Window { [STAThread] public static void Main() { Application app = new Application(); app.Run(new RecordKeyStrokes()); } public RecordKeyStrokes() { Title = "Record Key Strokes"; Content = ""; } protected override void OnTextInput(TextCompositionEventArgs e) { base.OnTextInput(e); string str = Content as string; if (e.Text == "\b") { if (str.Length > 0) str = str.Substring(0, str.Length - 1); } else { str += e.Text; } Content = str; } } }
1)Content属性的值发生变化后,屏幕会自动更新。