HWH....

导航

 

Content

1.You can set the Content property to a string, you can set it to a bitmap, you can set it to a drawing, and you can set it to a button, or a scrollbar, or any one of 50-odd controls supported by the Windows Presentation Foundation

2.You can only set the Content property to one object.

3.You cannot set the Content property to another object of type Window. You'll get a run-time exception that indicates that Window must be the "root of a tree," not a branch of another Window object.

4.String ..... Content = "Content can be simple text!";

 If you make the window too narrow to fit all the text, you'll find that the text is truncated rather than automatically wrapped (alas), but you can insert line breaks in the text using the carriage return character ("\r") or a line feed ("\n"), or both: "\r\n".

5.     FontFamily = new FontFamily("Times New Roman");
    FontSize = 48;//  point=FontSize*3/4=48*3/4=36-Point;

     FontStyle = FontStyles.Italic;
    FontWeight = FontWeights.Bold;

    FontStretch=FontStretches.Normal;  
There is no such thing as a Font class in the WPF.

Notice that the FontStyle, FontStretch and FontWeight properties are set to static read-only properties of the FontStyles (plural) and FontWeights (plural) classes. These static properties return objects of type FontStyle, FontStretch and FontWeight, which are structures that have limited use by themselves.

6.又一个Window类的重要属性:SizeToContent=SizeToContent.WidthAndHeight;根据内容调整宽度。
7.又一个Window类的重要属性:ResizeMode,对于Resize的相关设定、

8.StringBuilder and String Set into the Content...

StringBuilder不能正常的更新,Because the window has no way of knowing when the string stored by this StringBuilder object changes, so it doesn't update the window with the new text string.Have to Content = null;Content = build;

9.Image Properties.

 

    
Uri uri = new Uri("http://www.charlespetzold.com/PetzoldTattoo.jpg");
BitmapImage bitmap
= new BitmapImage(uri);
Image img
= new Image();
img.Source
= bitmap;
Content
= img;

 

Stretch=Stretch.Fill

Stretch.Fill     This setting causes the image to fill up the entire window

Stretch.None     This setting causes the image to be displayed in its metrical size, which is obtainable from the Width and Height properties of the BitmapSource

Stretch.Uniform  By default, This setting causes the image is increased or decreased in size uniformly

StretchDirection    If you use a Stretch option other than Stretch.None,

StretchDirection.Both       which means that the image can be stretched greater than or less than its metrical size

StretchDirection.DownOnly      then image is never larger than its metrical size,

StretchDirection.UpOnly               the image is never smaller than its metrical size

HorizontalAlignment

img.HorizontalAlignment = HorizontalAlignment.Right;

VerticalAlignment

img.VerticalAlignment = VerticalAlignment.Top;

Margin

img.Margin = new  Thichness(10);

Width, Height

Opacity

img.LayoutTransform = new RotateTransform(45);  //让图片旋转45度

 The Image class does not have its own Background and Foreground properties because those properties are defined by the Control class and Image is not derived from Control. The distinction may be a little confusing at first. In earlier Windows application programming interfaces, virtually everything on the screen was considered a control. That is obviously not the case here. A control is really just another visual object, and is characterized mostly by giving feedback to user input. Elements like Image can obtain user input, of course, because all the keyboard, mouse, and stylus input events are defined by UIElement.

 10.Shape ...Ellipse

Ellipse elips = new Ellipse();
elips.Fill
= Brushes.AliceBlue;
elips.StrokeThickness
= 96; // 1 inch
elips.Stroke = new LinearGradientBrush(Colors.CadetBlue, Colors.Chocolate, new Point(1, 0), new Point(0, 1));
elips.Width
= 400;
elips.Height
= 300;

//elips.HorizontalAlignment = HorizontalAlignment.Left;
//elips.VerticalAlignment = VerticalAlignment.Top;
elips.HorizontalAlignment = HorizontalAlignment.Stretch;  //for default
elips.VerticalAlignment
= VerticalAlignment.Stretch;     //for default
Content
= elips;
 
 

 

 

 11.UIElement.OnRender 方法,(FrameworkElement)

在派生类中重写时,会参与由布局系统控制的呈现操作。 调用此方法时,不直接使用此元素的呈现指令,而是将其保留供布局和绘制在以后异步使用。

OnRender 方法可以被重写以将其他图形元素(未事先在逻辑树中定义)添加至所呈现的元素,如效果或装饰器。 DrawingContext 对象作为参数传递,该参数可以为绘制形状、文本、图像或视频提供方法。

 12.What the Controls

Controls are designed to obtain input from users and put that input to work. You'll see how in the next chapter。

 

posted on 2011-03-22 16:22  HWH....  阅读(312)  评论(0编辑  收藏  举报