Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Illustrated WPF phần 2 ppt
Nội dung xem thử
Mô tả chi tiết
CHAPTER 2 ■ OVERVIEW OF WPF PROGRAMMING
32
• This code produces the window shown in Figure 2-13.
Figure 2-13. The resulting window
CHAPTER 2 ■ OVERVIEW OF WPF PROGRAMMING
33
Important Properties of a Window
When you look at a window on the screen, you’ll see several things. These include the client area, which
consists of its content and background, and the nonclient area, which consists of the window border and
the window bar at the top. The appearance of these items is controlled by five properties: Title, Content,
Foreground, Background, and WindowStyle.
The Window object is illustrated in Figure 2-14.
Figure 2-14. A few of the many important properties of the Window class
CHAPTER 2 ■ OVERVIEW OF WPF PROGRAMMING
34
WindowStyle
The WindowStyle property gets or sets the characteristics of the nonclient area, including the border style
and the buttons shown in the window bar.
The values that the WindowStyle property can accept are the following:
• SingleBorderWindow: This is the default style. It has the following:
− A plain single border around the client area
− A minimize, maximize, and close button in the window bar
− An application icon in the window bar
• ThreeDBorderWindow: This is similar to the SingleBorderWindow value, but the inside
of the border is beveled.
• ToolWindow: This is like the SingleBorderWindow value but doesn’t have the icon or
the minimize or maximize buttons in the window bar. Also, the border is thinner.
• None: This style has a thin border and no window bar.
The following code produces the top-left window shown in Figure 2-15. You can produce the
other three windows by changing the WindowStyle property.
[STAThread]
static void Main()
{
Window win = new Window();
win.Height = 75; win.Width = 300;
win.Title = "WindowStyles";
WindowStyle
↓
win.WindowStyle = WindowStyle.SingleBorderWindow; // Set property
win.Content = win.WindowStyle.ToString();
Application app = new Application();
app.Run( win);
}
Figure 2-15. Examples of the four different values of the WindowStyle property
CHAPTER 2 ■ OVERVIEW OF WPF PROGRAMMING
35
Content
Unlike previous frameworks for building Windows programs, the content of a Window object always
consists of a single object. That object might, in turn, contain other objects⎯but it’s still a single object.
I’ll explain much more about this in Chapter 5 and Chapter 6.
For example, the following code creates a button and assigns the button as the content of the
window:
public MyWindow()
{
Title = "My Program Window";
Width = 300; Height = 200;
Button btn = new Button(); // Create a button.
btn.Content = "Click Me"; // Set the button's text.
Set the button to be the window content.
↓
Content = btn;
}
Figure 2-16 shows the resulting window. When first looking at this window, some people have
trouble seeing the button immediately. That’s because it takes up the whole window.
Figure 2-16. A button as the content of a window