tailieunhanh - Programming C# 4.0 phần 10

Tham khảo tài liệu 'programming c# phần 10', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Content Row 1 3 columns wide Button 0 2 3 Content Row 2 3 columns wide Button 1 3 FontSize 50 Content 3 1 Grid Figure 20-2 shows how this looks. The four rows are fairly clear each button belongs to just one row. The columns are less obvious you can see all three clearly in the first row because there s one button in each but the next two rows contain just one button each spanning all three rows. And the final row contains a single button in the second column. Figure 20-2. Grid children The Grid knows which columns and rows elements belong to and how many they span because each button in Example 20-4 has properties that control this. The and properties do what their names suggest while the and properties determine how many grid cells the element occupies. The column and row default to 0 while the spans default to 1. 740 Chapter 20 WPF and Silverlight These properties use another special Xaml feature called attached prop-Ũ. 4 . erties. An attached property is one defined by a different type . Grid than the object it is applied to . Button . The attached properties in Example 20-4 are attributes but you can also set attached properties with the property element syntax shown earlier for example if a Grid element could contain a Tip element to set the attachable ToolTip property defined by the ToolTipService class. While Silverlight WPF and Xaml support the idea that properties don t necessarily have to be defined by the object on which they are set C has no syntax for this. So classes that define attachable properties also define get and set methods to enable those properties to be used from code. For example the Grid class offers SetColumn SetRow and so on. The rows and columns in Figure 20-2 are different sizes. This is because of the settings on the RowDefinition and ColumnDefinition elements. The first column s Width has been set to