Вы находитесь на странице: 1из 461

-

-
2010

681.3.06
32.973.26-018.2
75
75

. .

Silverlight 3. .: -, 2010.
464 .: .
ISBN 978-5-9775-0514-7

Web-
Microsoft Silverlight 3. ,
, . Web-,
Silverlight-.
Microsoft Visual Web Developer 2008 Express Edition, XAML C#, , , Silverlight-.
Silverlight . , Web-, . , Silverlight.
Silverlight-.
Web-
681.3.06
32.973.26-018.2

:

.
.

02429 24.07.00. 30.12.09.


701001/16. . . . . 37,41.
2000 .
"-", 190005, -, ., 29.
-
77.99.60.953..005770.05.09 26.05.2009 .
.

" ""
199034, -, 9 , 12

ISBN 978-5-9775-0514-7

. ., 2010
, "-", 2010

.................................................................................................................. 1
- ! .............................................................................. 1
Silverlight ......................................................................................................... 2
......................................................................................................... 2
........................................................................................................... 3
.................................................................................................. 4
...................................................................................................................... 5

I. SILVERLIGHT.
..................................................................... 7
1. Silverlight .............................................................................. 9
WWW ........................................................................................................ 9
: Web- ...................................................................... 9
: Web- .............................................................. 13
: Web- ............................................................. 14
Web- ....................... 16
HTML+CSS+JavaScript .............................................................................................. 16
Adobe Flash ................................................................................................................. 18
Sun Java ....................................................................................................................... 19
Microsoft Silverlight ............................................................................................................ 20
? ........................................................................................................................ 21

2. Silverlight.................................... 22
...................................................................................... 22
Silverlight- ................................................................................... 23
.................................................................................................................... 23
Silverlight- Web- ...................... 24
................................................................................................................ 25
................................................................................................................. 26

IV

Silverlight- .......................................................................................... 28
Silverlight-. ....................................................... 28
. .................................................................... 29
. ................................................. 31
, Silverlight- .............................................. 32
Silverlight-................................... 33
? ........................................................................................................................ 34

3. Silverlight- ............................................... 35
Microsoft Visual Web Developer 2008 Express Edition ..................................................... 35
. ................................................................................................ 39
Silverlight- ...................................................................................... 40
................................................................................................................ 42
Solution Explorer .................................................................................................... 43
Silverlight- ................................................................. 44
XAML ............................................................................. 44
. Toolbox ......................................... 48
Silverlight- .......................................................... 52
""............................................................................... 53
Silverlight- ......................................................................... 56
................................................................................................... 57
.................................................. 58
C# ................................................................... 59
C#, .......................................... 62
............................................................................................................. 65
Visual Web Developer 2008 .......................................................... 66
? ........................................................................................................................ 67

II. , , ,
........................................................................ 69
4. ............................................................ 71
, .................................................................................. 71
................................................................................................................................. 73
......................................................................................................................... 74
............................................................................................................. 75
...................................................................................... 75
............................................................. 77
............................................................................... 78
XAML-. ......................................................... 79
? ........................................................................................................................ 81

5. ................................................................... 82
........................................................................................................................ 82
"".................................................................................................. 82

"" .................................................................................................... 89
""...................................................................................................... 89
............................................................................................................................. 91
? ........................................................................................................................ 92

6. ...................................................................... 93
TextBlock .............................................................................................................. 93
TextBlock ..... 97
TextBox ............................................................................................................ 99
PasswordBox ..................................................................................... 102
Button ................................................................................................................... 103
CheckBox ............................................................................................................. 105
RadioButton ............................................................................................ 106
ListBox .................................................................................................................. 107
ComboBox .............................................................................. 109
Calendar.......................................................................................................... 110
DatePicker ............................................................................. 111
Slider ................................................................................................................ 111
ProgressBar .................................................................................. 112
ScrollViewer .................................................................................. 113
TabControl .................................................................................... 114
............................................................................. 116
? ...................................................................................................................... 119

7. ............................... 120
................................................................................................................. 120
Image...................................................................................................... 121
...................................................................... 122
.................................................................................... 124
MediaElement ........................................................................................ 124
.................................................. 126
? ...................................................................................................................... 127

8. .................................................................................. 128
................................................................................................ 128
.............................................................................................. 129
............................................................. 130
............................................................................. 132
.......................................................... 132
? ...................................................................................................................... 134

III. C# ....................................................................................... 135


9. C# ................................................. 137
, , , ............................ 137

VI

.................................................................................................................... 139
C#, Silverlight .................................................. 140
................................................................................................................. 140
........................................................................................................ 142
..................................................................................... 142
............................................................................................................... 143
.............................................................................................................. 143
......................................................................................................... 144
............................................................................................. 144
...................................................................... 144
.......................................................................... 145
...................................................................................................................... 146
......................................................................................... 146
. ........................................................ 147
........................................................................................ 148
, .......................................... 148
........................................................................................................................ 148
.................................................................................... 149
........................................................................................... 150
........................................................................................ 150
.............................................................................................. 151
............................................................................................. 152
.................................................................................................. 153
............................................................................................. 153
........................................................................................................ 155
......................................................................................................................... 155
............................................................................................... 155
................................................................................................... 157
........................................................................................................................ 158
.......................................................................................... 158
...................................................................................... 160
...................................................................................... 161
.................................................................... 161
....................................................................................................... 162
............................................................................................................................ 163
................................................................................................................ 165
.................................................................................................................... 166
? ...................................................................................................................... 167

10. C# ............................................................ 168


............................................................................................................. 168
...................................................................................................... 169
.................................................................................................................. 169
............................................................................................................. 169
........................................................................................................... 169

VII

........................................................................................................... 170
................................................................................ 171
............................................................................................. 171
........................................................................ 171
............................................................................................................ 172
............................................................................... 172
.......................................................................................... 172
............................................................................................. 173
............. 174
................. 176
null.................................................................................................... 177
................................................................................... 177
Silverlight................................................................ 177
Object ..................................................................................................... 178
String ...................................................................................................... 178
Math ....................................................................................................... 179
............................................................................... 180
................................................................................. 181
................................................................................................ 182
............................................................................................ 183
................................................................................. 186
............................................................................................ 187
................................................................... 189
......................................................................................................................... 190
............................................................................................. 190
Silverlight .......................................................... 191
Int16, Int32, Int64, UInt16, UInt32 UInt64 ................................................... 191
Double Single................................................................................................. 191
Decimal ............................................................................................................. 192
DateTime ........................................................................................................... 193
TimeSpan .......................................................................................................... 195
............................................................................. 196
...................................................................................................................... 196
................................................................................................................... 199
? ...................................................................................................................... 199

11. ........................................................................................ 200


.......................................................................................................... 200
........................................................................................................... 201
List .................................................................................................................. 201
List ............................................................................ 201
........................................................................... 202
....................................................... 202
.............................................................................. 203

VIII

...................................................................... 204
.............................................................. 205
Dictionary ........................................................................................................... 207
Dictionary ..................................................................... 207
............................................................................... 207
........................................................... 207
................................................................................... 208
........................................................................... 209
.................................................................................... 209
Queue .......................................................................................................... 210
Stack .................................................................................................................. 210
, ............................................... 211
? ...................................................................................................................... 212

12. ..................................................................................... 213


........................................................................................................ 213
.................................................................................................... 214
.................................................................................... 215
.................................................................................................... 216
......................................................................... 216
..................................................................... 218
............................................................................................ 219
? ...................................................................................................................... 220

IV. . LINQ ............ 221


13. ............................................... 223
............................................................................................................. 223
.......................................................................................... 224
Silverlight- .
............................................................................ 226
........................................................................................ 228
.................................................. 230
.................................................................................... 232
....................................................................... 233
.................................................................................... 234
...................................................................................................... 236
.......................................................... 236
.............................................................................. 237
. ........................... 239
............................................................................. 240
DataGrid ................. 241
DataGrid .................................................... 246
DataGrid ............................................ 247
? ...................................................................................................................... 248

IX

14. LINQ................................................................................................... 249


LINQ ................................................................................... 249
............................................................................................... 250
. ........................................................ 253
......................................................................................................... 254
.......................................................................................................... 255
.......................................................................................................... 256
........................................................................................................ 258
....................................................................................... 261
.
.................................................................................... 262

...................................................................................................... 264
......................................................................................... 265
? ...................................................................................................................... 267

V. SILVERLIGHT.
.................................................. 269
15. ............................................................................................. 271
......................................................... 271
....................................................................................................... 274
. .................................................................................... 276
....................................................... 276
. ......................................... 277
....................................................................................... 279
Border ............................................................................................................ 284
................................................................................................................ 285
....................................................................................................... 285
................................................................................................... 286
................................................................................................... 291
................................................................................................................. 293
.......................................................... 294
? ...................................................................................................................... 294

16. .......................................................... 295


........................................................................................................................... 295
................................................................................................. 295
......................................................................................... 296
............................................................... 298
................................................................................................................ 299
.................................................................................... 299
. ........... 303
................................................................................... 304
? ...................................................................................................................... 305

17. .......................................................................................... 306


Silverlight- ........................................................................ 306
....................................................................................... 308
...................................................................................................... 313
......................................................................................................... 317
............................................................................. 319
? ...................................................................................................................... 320

18. ................................................... 321


.................................................... 321
.................................................................. 322
...................................................................................................... 323
............................................................................................... 324
................................................................................................................. 326
............................................................... 328
- (HyperlinkButton).................................................................... 330
Web- .............................................................................. 331
? ...................................................................................................................... 331

19. ............................................................................... 332


.............................................................................................................. 332
................................................................................... 332
..................................................................................... 334
................................................................ 336
...................................................... 338
- ..................................................................................................... 340
? ...................................................................................................................... 342

VI. WEB- ..................... 343


20. .................................................... 345
............................................................................................. 346
................................................................... 346
......................................................................................................... 347
.................................................................................. 347
............................................................................................................ 349
........................................................................................................ 350
......................................................................................... 352
.............................................................. 353
........................................................................................ 354
.................................................... 354
................................................................... 356
.................................................................... 356
............................ 356

XI

...................................................................................... 358
................................................................. 359
................................................................... 361
? ...................................................................................................................... 363

21. .................................................... 364


........................................................................ 364
........................................................................... 365
WebClient ........................................................................................................ 365
............................................................................................. 366
........................................................... 367
................................................................ 369
.................................................................................... 370
................................................................................................... 370
.............................................. 371
? ...................................................................................................................... 374

22. Web- ................................................................. 375


Web- ..................................................................................................................... 375
..................................................................................................................... 376
..................................................................................................... 378
.................................................................................. 378
....................................................................................................... 380
......................................................................................................... 383
................................................................................... 386
Web-..................................................................................................... 387
Web- .............................................................................. 387
......................................................................................... 388
Web-.................................................................................. 390
................................................................................ 392
Silverlight-, Web- .. 392
Silverlight- Web- ............................................ 394
Web- ............................................................................ 395
Silverlight-, Web- .... 398
LINQ- Web- ................................................................ 399
............................................................. 401
, ............................................. 403
...................................................... 406
? ...................................................................................................................... 409

VII. .......................................................... 411


23. ............................................................................ 413
..................................................... 413
................................................................... 414

XII

.............................................................................. 415
..................................................................................... 418
? ...................................................................................................................... 420

24. Silverlight- ................................... 421


Silverlight-. .................. 421
......................................................... 422
, ................................................................................ 423
................................................................................................... 426
Silverlight- Web- .......................................................... 429
Silverlight- ............................................................................. 430
Silverlight-..................................................... 430
Silverlight- ...................... 432

......................................................................................................... 435
.................................................................................... 437


-! Microsoft Silverlight 3!
Web-! !
? ? Silverlight? , ?
Web-?

- !
,
. , , , , , ,
. ...
, , .
, . , Web-
, -...
! Web-, , Web-, Web-. Web-
Web-,
Web-, -
, , . , ( ...).
Web-
. ,
Adobe Flash. , Sun Java (
Oracle). , -

- , "" - HTML+CSS+JavaScript. ,
, Mozilla XUL, Microsoft ActiveX .
.
Microsoft Silverlight.
"" , . , ,
, .
. , , , , , .

Silverlight
Silverlight " "
1. .
 Web- , -

.
 .
 , (

), .
 , , .
 .
 Microsoft, -

SharePoint 2010.
 -

.
, , .
( Flash).


Silverlight Silverlight-. ,
, , , -

(Web-)
.
! .
Silverlight. , .


, . , Windows
.
1. Web- Silverlight.
Silverlight. Web- http://
go.microsoft.com/fwlink/?LinkId=128526.
2. Microsoft Visual Web Developer 2008 Express Edition. Web-, Silverlight-.

Visual Web Developer 2008 SP1. Silverlight 3 Tools


.

Web- http://www.microsoft.com/express/download/default.aspx
Visual Web Developer 2008,
Microsoft Visual Studio 2008 Express Edition, , , Visual Web Developer 2008. SP1. ;
Microsoft Visual Studio 2008 Express Edition .
Visual Web Developer 2008 , Microsoft SQL Server 2008 Express Edition Silverlight 2
Tools. Microsoft SQL Server 2008 Express Edition , . .
22 , .
Silverlight 2 Tools
Silverlight 3 Tools.
3. Silverlight 3 Tools. Visual Web Developer 2008, Silverlight 3.
Web- http://go.microsoft.com/fwlink/?LinkID=128219.

Silverlight 3 Tools
Silverlight. .

4. Silverlight 3.
Silverlight 3 . CHM Web- http://go.microsoft.com/fwlink/?LinkId=127106.
! .


, Silverlight-.
, .


. .

, (<>)
, . , , ,
<>. :
if (<>)


.
([]) . :
[< , >] < > < >

, .
[], , .
,
. :
string[] sPlatforms = {"HTML+CSS+JavaScript", "Flash", "Java",
"Silverlight"};

, .
 .

,
.
 , -

(. .),
, .
 .
 , .
 .
 .
 ,

.
 , -

"-", ,
.
 "-" .


.
 , Visual Web

Developer 2008 Silverlight 3, .


 , , .

Silverlight.

1.

Silverlight

2.

Silverlight

3.

Silverlight-

Silverlight

, Silverlight? , ,
Web-...
Web-? ?
... .

WWW
, . ? ? ,
, "" "", - ""?
(, , )
WWW. . ,
, (
-...).

: Web-
World Wide Web . Web-, HTML (Hypertext Markup Language ) ,
Web-. Web-, ( , -

10

I. Silverlight.

), Web-
( ). .
HTML , HTML.
;
, , ,
. ,
Web- .
Web- , ,
, Microsoft Windows.
Web- Web HTML, . ,
, Web-
txt, htm html;
Web- ,
.
Web- Web-,
, HTML , .
, . , , , , ,
HTML.
Web- Web-? --,
, .
, - Web-,
Web- -. - ,
Web-, :
http://www.compression.ru/all_anns.htm
, ? - Web- " ",
. http://www.compression.ru -
, , all_anns.htm
(, , ).
(/), , -.

1. Silverlight

11

- , , :
www.compression.ru/all_anns.htm
, , .
-, Web- ( http://www.compression.ru) . , Web- (all_anns.htm).
-:
http://www.compression.ru/video/index_ru.htm
Web- " ",
. Web-
Web- video/index_ru.htm.
- , , Web-. :
http://www.compression.ru/
, Web-
Web-.
, , , .
?
, Web. , , Web-,
, .
, Web-, Web-,
, Web. . Web-
, Web-.
Web- , Web-
. , - all_anns.htm , Web .
, Web-
, . ,
video/index_ru.htm (. ), Web-
index_ru.htm, video, , ,
.

12

I. Silverlight.

, ? Web Web- .
default.htm[l] index.htm[l] (
Web-) .
, , .
HTML
. ,
.
.
, Web- , -
. Web-, , Web-
, Web.
(Cascade Style
Sheet, CSS). HTML Web-, .
Web-.
Web-, HTML, . - , Adobe PDF, Microsoft
Word, Excel PowerPoint, Adobe Flash .
Web- , ; , Web- Web- Web.
,
, .

Web-. Web- , HTML


Web- - ( , , .). JavaScript .
Web- YouTube (http://www.youtube.com/).
HTML, -

1. Silverlight

13

,
CSS, ,
"" Web-.

: Web-
,
. Web , , . , ...
. , ,
. , ,
"" , ,
, , . !..
- ,
? , Web-, Web-
Web- ,
? !
, Web- -
( Web-) Web- ,
. ,
Web- ,
. !
- .
, Web-
, , .
, Web- , .
, ! Web- ( ) !
Web-
Web-, Web-, , , Web-. .

14

I. Silverlight.

, , Web- (
). ,
, "". (
.)
HTML .
Web- Web-,
. : ,
, , , ., .
,
" " . Web-, -, . , , Web-
( . 1.1).

. 1.1. Web- Web- Web- Mail.ru

: Web-
, - . ,
, ( ).
Web-
( , )
, , . , , , ,
.
. , , Web . Web-

1. Silverlight

15

! , ! Web-
, .
.
Web- ,
Web- ,
.
Web- , Web- ,
Web-,
. ,
, ,
, - ,
, .
!

. 1.2. Web- RSS

16

I. Silverlight.

Web- - ... , CSS, , ...


( ) Web- ,
. , "15", , ...
, Web-, Web-. . . 1.2.
,
. .


Web-
, , Web :
 ;
 ;
 ( ,

);
 ,

;
 ,

( ). , .
Web- .
.

HTML+CSS+JavaScript
Web- -: HTML, CSS Web-, JavaScript.
, Web-.

1. Silverlight

17

Web- Web- Web-.



. JavaScript ,
.
Web- Windows-,
: , , , , , ,
, , .
, , ,
Ext (http://www.extjs.com/). , . 1.2 , .
:
 HTML, CSS
JavaScript, Web-;
 HTML, CSS JavaScript
Web-;
 . ,
!
:
 -,
HTML, CSS JavaScript; ;
 ;
 -.
. , ,
, Web- HTML-
Web-. .
Web- , Web-, ,
. -.
. JavaScript . Web- Web-,
, , , . . .
, ""
HTML+CSS+JavaScript , - -

18

I. Silverlight.

. , , . , , ,
.
.

Adobe Flash
Flash FutureSplash
90- . 1996
Macromedia, , , 2006 Adobe.
Flash Web- ,
Web. Flash CS4 . ActionScript.
Flash Web-
Flash.
Flash ,
, Flash .
:
 ,
, .;
 ActionScript;
 ;
 -.
-, Flash -!
JavaScript, ActionScript . Flash
() , . , , ,
, , .

.
.

1. Silverlight

19

Flash:

Web- , . , , ,
Flash;
 ActionScript;
 Flash ;
 Flash Flash (, ,
);
 Flash , , Adobe Flash Professional CS4.
Adobe Flash , Web-. , ,
!..

Sun Java
Java Sun 1995 .
; "" , , Web-. ,
, Sun...
Java. ; Java ( Sun "-"). Java Java.
Java, , , "" Flash:
 ,
.;
 Java;
 ;
 ;
 -.
:
 Java;
 Java ;

20

I. Silverlight.

 Java -

Java, .
Java , Flash. Java
Web-.

Microsoft Silverlight

Microsoft Silverlight. , . !
Silverlight 2007 . ,
, Web-
. 2008 , , . 2009 . - .
Silverlight ""
Microsoft .NET. , Web-, Web-.
:
 , .NET, , Visual Basic C#;
 ,
, .;
 -

. ,
Microsoft Visual Studio 2008 Express Edition, Microsoft (http://www.microsoft.com/);
 ;
 ;
 -.

, Silverlight . , ""
"".
:
 Silverlight -

1. Silverlight

21

 Silverlight (-

Microsoft).
! , , .
, HTML+CSS+JavaScript, Flash Java! Silverlight !

?
.
, Silverlight-,
. 3,
, - Silverlight-.


Silverlight
WWW, , Web-,
.
""
Microsoft Silverlight 3.
Silverlight. , Silverlight, :
, . , Silverlight
.
. ...


: . .
,
"" . "" Windows- ,
, .
Web- , : Web, .
"", Web- . ,
1. Web-

2. Silverlight

23

""
.
"" ,
( , , .).

.

. , Web-, HTML+CSS+
JavaScript, HTML CSS, JavaScript. Web Flash , , ActionScript.
Silverlight , .

Silverlight- .

Silverlight-
, ""
.

Windows-
. Web- Silverlight
.

Silverlight- Web-!
.

Windows-, .
, , .
Silverlight; Silverlight-.
Windows, , Windows-. ,
, .
Silverlight , Web-
"" Silverlight-; ,

24

I. Silverlight.

, Web- Silverlight .
Windows- ,
. Windows : , , , -, .
, , ,
, .
Windows- ,
, , . , , , . ,
.
Silverlight- - ,
. .
Silverlight- , ( 18 19).
- Silverlight 3 , . ,
, , .
Silverlight 3 . ...

Silverlight-
Web-
Silverlight- .
Web- Silverlight . ( Web- 1.)
, , HTML-
Web- HTML, -
. , Web- Web-,
,
Web- .

2. Silverlight

25

, Silverlight- , Web- . (,
: ,
- , Adobe PDF .)
, Web-,
Web- Silverlight.
Web-.
Silverlight-
Web-. Web-
Silverlight . ,
, Silverlight-.

" ". " " ( , , , ,


.), , , ,
, . "",
(, , , .).
" " . "" , "" ,
,
.
"" .
" "
Silverlight . ,
.
-, ,
. ,
, .
-, " ". . , , . , , , ,
.

26

I. Silverlight.

, Silverlight, , "" .

, : ( )
.
...
, . , , ,
!.. -
; , .

? .
:
 "" , ;
 , ;
 , ;
 ,
.

. , . , .
Silverlight.
, ; ,
.
(),
.
: ,
. .
Silverlight .
 "". -

. ,
. .

2. Silverlight

27

 "". -

.
 "". , -

.
. 2.12.3 , , .

. 2.1. ""

Y1

Y2

Y3

X1

. 2.2. ""
(
)

X2
X3
. 2.3. ""

. 2.4 .
"" "" "" .
Silverlight-
. , ...
.

28

I. Silverlight.

""


""

""

. 2.4.

Silverlight-
, . , . , - , ! ,
, , .
.

Silverlight-.
, Web- Web- Silverlight. Web-, Web , Silverlight-, .
?
... .
?
.
, , Web-, . , "",
" ", , , " ".
;
.
Silverlight ,
.

2. Silverlight

29

"" Silverlight.
, .
? .
, .
, -, , -, , .
, ,
.
, Silverlight-,
, , . ;
.
,
, "", -.
Silverlight- . !

.
, . , ,
.
. , " ". , . (, ), (, )
, .
,
, .
, .
, .
"" .
?
, Silverlight
, .

30

I. Silverlight.

" " ,
, .
.
, .
. ,
,
, .
, , ,
.
, . , ,
. ; ,

, .
, :
 ,

, , , , .;
 ,

.;
 , , -

.
Silverlight- ! . ,
, .
Silverlight!
, . , .
. ,
, ,
. "", , .
, ,
" " , ,

2. Silverlight

31

" ". "". "".


.
.
, ,
(. .
; ).
, .
. ,
(, ,
).
;
, .
, ,
, . .
, , .
.

.

, ,
. , Silverlight, Microsoft.
Silverlight-.

- Windows-. ,
. , "" ,
( , ), . ,
,
.
, , , .
, , ?

32

I. Silverlight.

. , .
, , . ,
, , . ,
, , ,
. ;
,
,
.
, , ,
, , . , , - "" , .
.
- ,
. ,
.
, " ",
"", .
.
"", ,
, .
Silverlight , , . "" ;
. !

,
Silverlight-
, , Silverlight-.
, , ,
. ,
( ), ,

, . .

2. Silverlight

33

, , . .
, .
. -, , , (, )! ...
1. , , .
2. .
3. ( , , ) ,
.
, ,
Silverlight-. . ,
.
. , .

, , , .


Silverlight-
, ,
Web-
Silverlight. - .

XAML (eXtensible Application Markup Language
; "").
XML (eXtensible Markup
Language ). , XAML , ; , , , , , . ( XAML HTML,
.)
, .NET,
, Visual Basic C#. C# ( "-").

34

I. Silverlight.

XAML ,
Microsoft . C#
"" MSIL
(MicroSoft Intermediate Language Microsoft).
Silverlight.
--! , ? - ?

?
,
,
. ,
.
.
Microsoft Visual Studio 2008 Express Edition,
, Silverlight,
XAML C#. !


Silverlight-
, .
, , , , . ,
Silverlight- :
XAML C#.
Silverlight-.
Microsoft Visual Studio 2008 Express Edition, ,
Microsoft Visual Web Developer 2008
Express Edition, Web-, . , , XAML
C#.

Microsoft Visual Web Developer 2008


Express Edition
Microsoft Visual Web Developer 2008 Express Edition, ,
, Microsoft Visual Studio 2008 Express
Edition Web-.
Silverlight 3 Tools , ,
Silverlight 3.
.
Visual Web Developer 2008 (
, ). (Start),
(Programs)
(All Programs),

36

I. Silverlight.

Microsoft Visual Web Developer 2008 Express Edition. (. 3.1).

. 3.1. Microsoft Visual Web Developer 2008 Express Edition

, , . Visual Web Developer 2008


, ,
.
, .
;
, . ,

. . 3.2 Solution
Explorer, ; , , Visual Web
Developer 2008, .
,
.
 "" .
 "" -

( "", , -

3. Silverlight-

37

. 3.2; Solution Explorer Database


Explorer). ""
, "" ;
.

. 3.2. Solution Explorer ()

 "" .
 ( ). -

,
. . 3.3 ,
Toolbox,
CSS Properties Manage Styles. ,
(. 3.4);
, .
. , Visual Web Developer 2008.
. , ,
( ,
Windows).

38

I. Silverlight.

. 3.3. ,
Toolbox,
CSS Properties Manage Styles

. 3.4. Toolbox,

. , ,
. ;
. . 3.5.
Visual Web Developer 2008 . , , ,

3. Silverlight-

39

Microsoft, Web-; , ,
.

. 3.5.

(
). - Silverlight-.

.
- . .
1 2, Silverlight-
XAML C# ( , MSIL; C#). . , . ,
Silverlight,
, .
, ,
( ). (,
) : XAML-,
C#-. , , Visual Web Developer 2008,
. ,
, Visual Web Developer 2008.
,
. - ,
" " . ?
( Visual Web
Developer 2008 ) . , :
 ;
 (, , ,

. .);

40

I. Silverlight.

 (, Silverlight- -

Web-, Web-).
, ,
. ,
.
, , .
. Visual Web Developer 2008 .
Visual Web Developer 2008 . , .

Silverlight-
Silverlight- ( )
, New Project File
<Ctrl>+<Shift>+<N>. New Project
(. 3.6), (
).

. 3.6. New Project

3. Silverlight-

41

Visual Web Developer 2008,


Silverlight-,
C#. Project types "" Visual C#,
Silverlight .
Templates Silverlight Application, . . Silverlight-.
, , . Name.
, ,
Convertor.
(
), Create directory for solution. , ,
.
OK. ?
. Visual Web Developer 2008, ,
Web-
Silverlight-. New Silverlight Application (. 3.7).

. 3.7. New Silverlight Application

,
Visual Web Developer 2008 .
Host the Silverlight application in a new Web site. OK.
Visual Web Developer 2008
. . 3.8. !

42

I. Silverlight.

. 3.8. Visual Web Developer 2008


Silverlight-,
Visual Web Developer 2008, .
?
, . ,
XAML,
( ,
).
? , Visual Web
Developer 2008, . , ,
.
Visual Web Developer 2008
.
, .
, -
. Visual Web

3. Silverlight-

43

Developer 2008. , , ;
, .
, , .

Solution Explorer
Visual Web Developer 2008, , Solution Explorer (. . 3.2).
, , .
Solution Explorer , , Solution Explorer View
<Ctrl>+<Alt>+<L>.
Solution Explorer . Visual
Web Developer 2008 , .
( ),
( . 3.2).
"" Solution Explorer . "" "".
 "" Properties -

. 24.

 "" References , .

4.

 "" App.xaml

XAML, .
13.
 "" MainPage.xaml

XAML, (
).
,
"" MainPage.xaml. -
MainPage.xaml.cs. C#, (
).
.
: , XAML,
xaml, C# xaml.cs.

44

I. Silverlight.

: , , Visual
Web Developer 2008 MainPage. ,
: MainPage.xaml MainPage.xaml.cs.
: , ,
App. : App.xaml App.xaml.cs.
Solution
Explorer, .
.
Silverlight-, Visual Web
Developer 2008 , XAML
. , MainPage.xaml.
.
, .


Silverlight-
XAML ( ):
<UserControl x:Class="Convertor.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot">
</Grid>
</UserControl>

?..

XAML
- , XAML.
.
XAML Silverlight. 1. ,
.
2 ,
, . . : XAML ,

3. Silverlight-

45

, ,
.
? -, , . -, ,
. -, .
, Silverlight-
-. 2 ,
, . ,
-, , .
, XAML .
, , XAML. ,
,
. , .
XAML , <
>. ( 2, ; , .)
<
.
XAML : ; .
, : , < >. <
/; . , , .
,
XAML:
<TextBox></TextBox>
TextBox

, "

".
( ).
:
<TextBox />

46

I. Silverlight.

, /.
, Visual Web Developer 2008
XAML .

- .
, . :
 XAML, , -

;


;
 < >="< >", -

.
, ,
" ", Text TextBox (. . ),
XAML;
<TextBox Text=" "></TextBox>

, , .
,
60 , MaxLength.
60.
<TextBox Text=" " MaxLength="60"></TextBox>

, .

XAML. , .
<TextBox Text=" " MaxLength="60" />

/ .
,
/ . - XAML
.

- . ?

3. Silverlight-

47

.
<Grid></Grid>

XAML Grid "" ( 2). .


XAML, , ""
.

<Grid>

<Grid>
<TextBox Text=" " MaxLength="60" />
</Grid>

- . ,
. ,
, () , "" , . .
:
<Grid>
<TextBox Text=" " MaxLength="60" />
<TextBox Text=" " MaxLength="40" />
<TextBox Text=" " />
</Grid>

"" .
? XAML ? .
XAML, Visual Web
Developer 2008 ,
. <UserControl>.
<UserControl x:Class="Convertor.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</UserControl>

2, Silverlight- , .
.
, UserControl ,
. , ,
Convertor.MainPage x:Class <UserControl>.

48

I. Silverlight.

x:Class .
. Visual Web Developer 2008
Silverlight , UserControl.
<UserControl>, , .
4. , Silverlight-, .
- <UserControl> .
, , ,
, ,
.

<UserControl> <Grid>, "":


<Grid x:Name="LayoutRoot">
</Grid>

( 2).
<Grid> x:Name LayoutRoot.
.

.
Toolbox
2 ,
. , , .
, . , !
, MainPage.xaml, XAML
. , "" Solution
Explorer (. . 3.2) .
,
Toolbox.
. , ,
Toolbox View
<Ctrl>+<Alt>+<X>.
XAML, Toolbox
,
Silverlight ( . 3.4). .

3. Silverlight-

49

"": Silverlight XAML Controls General.


"", Visual Web
Developer 2008 ; "" .
, ,
. , , .
TextBlock. ""
Silverlight XAML Controls TextBlock,
. ,
Toolbox, ,
, .
<Grid x:Name=
"LayoutRoot"> </Grid>, . . , .
.
Visual Web Developer 2008 XAML- , , .
XAML-,
, (, , ):
<Grid x:Name="LayoutRoot">
<TextBlock></TextBlock>
</Grid>

( , ). ,
, .
Text, TextBlock.
, . ,
XAML <TextBlock> .
TextBlock > . ... , !
Visual Web Developer 2008 (. 3.9).
, , Visual Web Developer 2008, .
- ,
, <Enter>.
, , <Esc>
.

50

I. Silverlight.

. 3.9.

, .
, , , .
Text Text.
Visual Web Developer 2008 <TextBlock>,

.
"".
! , Visual Web Developer 2008 .
, . XAML-, :
<Grid x:Name="LayoutRoot">
<TextBlock Text=""></TextBlock>
</Grid>

, !..
. <TextBlock>, TextAlignment (
) Right (). Text=""
TextAlignment.
Visual Web Developer 2008 , , Right. !
<Grid x:Name="LayoutRoot">
<TextBlock Text="" TextAlignment="Right"></TextBlock>
</Grid>

, . Toolbox
XAML- TextBox .

3. Silverlight-

51

<TextBox>, Text,
0. .
, ,
Silverlight .
Width (), Height () TextBox . 100 22 ,
<TextBox>.
XAML- :
<Grid x:Name="LayoutRoot">
<TextBlock Text="" TextAlignment="Right"></TextBlock>
<TextBox Text="0" Width="100" Height="22"></TextBox>
</Grid>

, , . ,
XAML, , ,
, ,
. :
<Grid x:Name="LayoutRoot">
<TextBlock Text="" TextAlignment="Right"></TextBlock>
<TextBox Text="0" Width="100" Height="22"></TextBox>
<TextBlock Text="" TextAlignment="Right"></TextBlock>
<TextBox Text="0" Width="100" Height="22"></TextBox>
</Grid>


, , . , IsReadOnly ( ) true (, ""). , Visual Web Developer 2008 , .
( XAML-,
):
<TextBox Text="0" Width="100" Height="22" IsReadOnly="true"></TextBox>

,
. Button.
"" .
.
Content Button. <Button>.

52

I. Silverlight.

XAML- :
<Grid x:Name="LayoutRoot">
<TextBlock Text="" TextAlignment="Right"></TextBlock>
<TextBox Text="0" Width="100" Height="22"></TextBox>
<Button Content=""></Button>
<TextBlock Text="" TextAlignment="Right"></TextBlock>
<TextBox Text="0" Width="100" Height="22" IsReadOnly="true"></TextBox>
</Grid>

, <Ctrl>+<S>. .
, -, ,
. , Visual Web Developer 2008
, . , Web-...


Silverlight-
, Visual Web Developer 2008 .
Silverlight- Visual Web Developer 2008 Web-, HTML-.
, , , Web-
Web-.
Silverlight- Visual Web Developer 2008,
:
 Start Debugging (

) ;

 Start Debugging Debug;


 <F5>, , , .

, , , .
, , ...
, , . 3.10.
-, , . ,
...
Web-, .
!

3. Silverlight-

53

. 3.10. Silverlight-
Web-

""
2 , ""
. ,

( ).
"", -, , -,
.
, "" (. . ) "" .
. 3.10.

Grid RowDefinitions ColumnDefinitions .
, , .
, ( ) ; , , .

.
.
. RowDefinitions Grid.
, . <Grid>,
, XAML
<< >.< >></< >.< >>

54

I. Silverlight.

,
, , .
. Toolbox
.
:
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
</Grid.RowDefinitions>
. . .
</Grid>

XAML-, "",
, .
.
.
, RowDefinition, .
XAML. ,
.
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
. . .
</Grid>

. . Height
RowDefinition .
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
</Grid.RowDefinitions>
. . .
</Grid>

.
ColumnDefinitions Grid;

3. Silverlight-

55

ColumnDefinition, . - Width
ColumnDefinition .
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
</Grid.ColumnDefinitions>
. . .
</Grid>

- , .
:
Grid.Row="< , >"
Grid.Column="< , >"

, , ,
, ,
.

, ,
.
, ,
( ):
<TextBlock Grid.Row="0" Grid.Column="0" Text=""
TextAlignment="Right"></TextBlock>


, .
XAML-:
<TextBlock Grid.Row="0" Grid.Column="0" Text=""
TextAlignment="Right"></TextBlock>
<TextBox Grid.Row="0" Grid.Column="1" Text="0" Width="100"
Height="22"></TextBox>

56

I. Silverlight.

<Button Grid.Row="1" Grid.Column="1" Content=""></Button>


<TextBlock Grid.Row="2" Grid.Column="0" Text=""
TextAlignment="Right"></TextBlock>
<TextBox Grid.Row="2" Grid.Column="1" Text="0" Width="100" Height="22"
IsReadOnly="true"></TextBox>

.
. . 3.11. , , ,
.

. 3.11. Silverlight-

.
...

Silverlight-
. .
MainPage.xaml.cs, C#, . , "" MainPage.xaml
Solution Explorer (. . 3.2)
MainPage.xaml.cs. .
. , :
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
}

3. Silverlight-

57

MainPage class. (
, , , .)
UserControl , MainPage
.
, . , MainPage
. ,
. (: .)
MainPage ,
, , MainPage.
, .
, .
, ! . , ,
,
. - !


: ,
?
: - .
( )
x:Name. XAML,
. .
.
 , -

, .
 , . .

.
, . .

58

I. Silverlight.

:
 txtInches;
 btnConvert;
 txtMillimetres.

MainPage.xaml, . XAML x:Name, . XAML-, , (


x:Name ):
<TextBox x:Name="txtInches" Grid.Row="0" Grid.Column="1" Text="0"
Width="100" Height="22"></TextBox>
<Button x:Name="btnConvert" Grid.Row="1" Grid.Column="1"
Content=""></Button>
. . .
<TextBox x:Name="txtMillimetres" Grid.Row="2" Grid.Column="1" Text="0"
Width="100" Height="22" IsReadOnly="true"></TextBox>

, XAML, ,
, LayoutRoot (
):
<Grid x:Name="LayoutRoot">
. . .
</Grid>

Visual Web Developer 2008 . ,


.
MainPage.xaml. .


!
. ""
btnConvert.

.
< >="< >". -,
, .
Button Click " ". ,
.

3. Silverlight-

59

<Button> Click, . Visual Web Developer 2008


, . ,
; .
, <New Event Handler>, . .
Visual Web Developer 2008 :
 , ,

, ;
 C# MainPage.xaml.cs,
MainPage,

"" .

, . XAML-,
( , ,
):
<Button x:Name="btnConvert" Grid.Row="1" Grid.Column="1"
Content="" Click="btnConvert_Click"></Button>

2, ( )
. Visual Web Developer 2008 , , , .
MainPage.xaml. MainPage.xaml.cs,
.

C#
C#-, Visual Web Developer 2008
, . :
private void btnConvert_Click(object sender, RoutedEventArgs e)
{
}

btnConvert_Click. , ,
void. ,
. ( , , , , 2.)

60

I. Silverlight.

, , .
 , , ,

. . , (,
, - ).
 , , ,

.
( ), .
, .
 sender object.
object Silverlight, , , . ,
( btnConvert).

 e
RoutedEventArgs.

RoutedEventArgs,
.

( ). .
txtInches ,
txtMillimetres. , .
, txtInches . ,
, . ( ) C# string.
C#-,

. :
btnConvert_Click.
string sInches;

C#! ( , .)
, .
string ()
sInches. Visual Web Developer 2008,

.

3. Silverlight-

61

, ;. , , .
,
txtInches. , :
sInches = txtInches.Text;

. ,
=.
txtInches Text,
. . Visual Web Developer 2008, Text
txtInches.
= , .

sInches. = C#,
.
, ,
, , .
, , sInches Text txtInches.
. , txtMillimetres , txtInches,
".". .
, ,
:
txtMillimetres.Text = sInches + ".";

+ , .
, ( sInches)
( ".") , .
,
, . , :
[< >.]< >
([< , >])

Focus txtInches, , , .
txtInches.Focus();

62

I. Silverlight.

. , ,
, .
! MainPage.xaml.cs .
- .
, ',
.

C#,

25,4 . , ,
txtInches, 25,4, .
Text TextBox . , , . , Visual Web
Developer 2008 .
.
, , . Silverlight . .
, ( ).
, , :
< >.< >
([< , >])

, , .
.
, , .
, ""
, bool.
: true ("") false ("").
true , ,
false (, - , "",
).
double
. , ?

3. Silverlight-

63

, . , .
string sInches;
double sgInches, sgMillimetres;
bool isConverted;

:
 sInches ,
txtInches;

 sgInches sgMillimetres -

;
 isConverted , -

.
sInches = txtInches.Text;

sInches ,
txtInches.
isConverted = double.TryParse(sInches, out sgInches);

.
TryParse double (-,
double , , , ).
:
 (
sInches);

 , , ,

, (sgInches). out
, ,
, .
, TryParse
true, false.
isConverted .
, . .
if (isConverted)
{
sgMillimetres = sgInches * 25.4;
}

64

I. Silverlight.

if , .
, if
( isConverted), , true, , . false, .
,
sgInches ( ), 25,4 sgMillimetres. , isConverted true, . . txtInches
, sgInches , .
25,4.
25.4. C#
.
else
{
sgMillimetres = 0;
}

, if
false, ,
else . sgMillimetres 0.
txtMillimetres.Text = sgMillimetres + ".";

, ... .
( sgMillimetres) ("."), Silverlight , , . !
.

. MainPage.xaml.cs .
, ,
.
, .
, Silverlight- - !

3. Silverlight-

65


.
, ...
Visual Web Developer 2008 . ,
, , . , , ; ,
...
, , Visual Web
Developer 2008 -, . -, , Yes. -,
,
No. .
, Visual Web
Developer 2008 Error List (. 3.12).
;
Description (-), File ,
, Line , Column
. - , .

. 3.12. Error List

, Error List,
, Visual Web Developer 2008 ,
.
,
; .
, Visual Web
Developer 2008 Output, ,
. Error
List, .
, .
.

66

I. Silverlight.


Visual Web Developer 2008
Visual Web
Developer 2008. .
, , .
, <Ctrl>+<S>. Save < , >
( ) File.
,
<Ctrl>+<Shift>+<S>. Save
All ( ) File.
, ,
. , ,
, Solution Explorer. Close File.
, ,
Close Project File.
Open Project File <Ctrl>+<Shift>+<O>.
Open Project,
Windows. ( csproj),
, Close Solution,
.

Open Project Close


Solution, Visual Web Developer 2008 . Add to
Solution, ,
. (
.)

Visual Web Developer 2008 , . Open


File ( ) , File
<Ctrl>+<O>. -

3. Silverlight-

67

Open File,
Windows. .
Visual Web Developer 2008
. Exit File.

?
, Visual Web Developer 2008
. -
Silverlight-!
- , ,
.
.

68

I. Silverlight.

II

, ,
,

4.

5.

6.

7.

8.


- Silverlight. " " Visual Web
Developer 2008, XAML C#, ,
, . !
, ,
, .
20 .
, ,
. , , .

,

,
Silverlight- Converter. Visual Web
Developer 2008 < >\Visual Studio 2008\Projects.
, , Visual Web Developer 2008
, . .
? .
.
 , , csproj.

"" ; ,
.

72

II. , , ,

 ,

, csproj.user.
 ( ), , , , sln.
Visual Web Developer 2008 ,
. , .

 ,

, suo.
 , XAML-, ,
, xaml.
 , C#-, ,
, xaml.cs.
,
, Visual Web Developer 2008 ;
XAML-, C#-.
( ), .
App,
,
App.xaml App.xaml.cs, MainPage.xaml MainPage.xaml.cs.
.
.
Properties .
, , , .
, Visual Web
Developer 2008 ( , 24).
obj , Visual Web Developer 2008 .
, .
, , , App.g.cs
MainPage.g.cs. C# App MainPage
; Visual Web Developer 2008 .
Bin .
Debug, .
, .

MainPage.

4.

73

...
 ( ), -

. DLL,
.
 , ;

. AppManifest.xaml.
.
.
 . ZIP, ,

, xap
. -, .
 Web-, ,

. Web.
.
 , , , pdb. Visual Web
Developer 2008 ( Visual
Web Developer 2008 ).

?..
Visual Web
Developer 2008, , .
, (
), exe. Silverlight- dll, . . Windows. Silverlight.
, . (
) ( ,
), , Windows. Visual Web Developer 2008
, .
, .

74

II. , , ,

, Silverlight-? . : , , .
Silverlight.
Silverlight , . , , .
, - , . ,
Visual Web Developer 2008
. (
Converter) .
, ,
3 Solution Explorer (. . 3.2). "" References,
. ""
.
, , . Silverlight .NET
, .
Visual Web Developer 2008, "" .
, .
, Silverlight 3 Tools
; (
), .
Visual Web Developer 2008.
,
, Visual Web Developer 2008 .
, , .
, ""
References Solution Explorer Add Reference. Add Reference (. 4.1).
: ,
, OK. ,

4.

75

, Component
Name . ,
Cancel.

. 4.1. Add Reference


""
References Solution Explorer
Remove.



. .


, ,
. , ,
, ( ),
.

( ). -

76

II. , , ,

"" :
, , ,
, , , (,
.).
Silverlight . ,
TextBox ( ) Controls,
Windows, , , System.
, , . -. , -
, -
.
,
(, System.Windows.Controls).
, , .
Visual Web Developer 2008 , .
.
MainPage.xaml.cs :
namespace Convertor
{
. . .
}

namespace . , , , , .
, .
, . ,
, , .
, ,
, :
namespace Converter
{
namespace Converter_Inner

4.

77

{
. . .
}
}

Converter_Inner
Converter. ...


C#.
.




.
.
. , ,
"" "". , .
, .
:
namespace Converter
{
namespace Converter_Inner
{
. . .
}
}

Convertor_Inner :
Convertor.Convertor_Inner.
, .
"" . , Converter
Converter.

78

II. , , ,


, , , , ,
.
namespace Converter
{
namespace Converter_Inner
{
class DataClass
{
}
}
}

DataClass

Convertor.Convertor_Inner.DataClass. TextBox
System.Windows.Controls.TextBox, String System.String.

! XAML- <UserControl>, , x:Class, ?


Convertor.MainPage. !


, Silverlight ,
. , -,
( TextBox ...),
- -, !
. , 3 ,
String System.String. ?
, Visual Web Developer 2008 . ,
,
, .
C#. using,
. ;
.
.
C#, . , Visual Web Developer 2008
"" .

4.

79

C#:
using
using
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Net;
System.Windows;
System.Windows.Controls;
System.Windows.Documents;
System.Windows.Input;
System.Windows.Media;
System.Windows.Media.Animation;
System.Windows.Shapes;

Visual Web Developer 2008.


.
,

. ,
.

XAML-.
C#-. XAML-?
.
XAML . .
XAML , C#. .
2, XAML
, Silverlight .
Silverlight, " " ,
MSIL, C#.
, .
, , Visual Web
Developer 2008. xmlns
<UserControl>, .
:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

,
XAML , . -

80

II. , , ,

, Silverlight.
xmlns <UserControl>:
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

.
, x:
(x:Class, x:Name ). , ( ).

, ,
<UserControl> xmlns :
xmlns:<>="clr-namespace:< >;
assembly=< , ,
 >"
. ,
.

, , :
<<, >:< >>


, .
.
Calendar. ,
. Calendar Toolbox XAML- , .
, <UserControl> , Visual Web Developer 2008:
xmlns:controls="clr-namespace:System.Windows.Controls;
assembly=System.Windows.Controls"

"" System.Windows.
Controls, System.Windows.Controls.dll, ,
controls. ,
, ,
System.Windows.Controls.

4.

81

, Calendar:
<controls:Calendar></controls:Calendar>

, Calendar
controls. Visual Web Developer 2008 , System.Windows.Controls.dll, .
, , , Toolbox. Visual Web Developer 2008
XAML- : ,
, , , .

?

Silverlight: , , , . .

Silverlight: , , ,
. .


, , . ,
Silverlight.
Silverlight.
, Silverlight-.
Silverlight; .

Silverlight . 2, Silverlight-, "", "" "".


.

""
"" ,
.
"" Grid. ,
<UserControl> .
"" <Grid>, , : , , , .

5.

83

<Grid>
<TextBlock Text=""></TextBlock>
<TextBox Text="0" Width="100" Height="22"></TextBox>
<Button Content=""></Button>
<TextBlock Text=""></TextBlock>
<TextBox Text="0" Width="100" Height="22" IsReadOnly="true"></TextBox>
</Grid>

"", Width Height Grid. , .


(Double), (. . ).
<Grid Width="400" Height="300">

, , ,
, ("" ). , .
Web- "" . Grid:
 MaxWidth , -

 MaxHeight , -

 MinWidth , -

 MinHeight , -


(Double),
.
<Grid MaxWidth="600" MaxHeight="400" MinWidth="100" MinHeight="100">

Margin ,
,
. :
< >,< >,< >,< >

84

II. , , ,

, ,
.
<Grid Margin="5,10,5,10">

: HorizontalAlignment VerticalAlignment.
"" , , .
. , (),
. - .
.
, , (. . , ). ,
.
! HorizontalAlignment
HorizontalAlignment. :
 Left ;
 Center
;
 Right ;
 Stretch ,
.
VerticalAlignment VerticalAlignment.
:
 Top ;
 Center
;
 Bottom ;
 Stretch ,
.
- ,
Silverlight , Stretch ( "" -

5.

85

). , .
<Grid Width="400" Height="300" HorizontalAlignment="Left"
VerticalAlignment="Bottom">

Grid ShowGridLines. ; true


, false . , false.
<Grid ShowGridLines="true">

ShowGridLines, , , ,
.
.
, ,
, , .
Visibility.

Visibility,
: Visible ( ; ) Collapsed
( ). ,
.
Visibility ,
C#-.
<Grid x:Name=grdContainer"" Visibility="Collapsed">
. . .
grdContainer.Visibility = Visibility.Visible;

, C#- . ( Visibility),
,
(Visible).
"" , ,
, .
. ,
,
( ). , "" , . ,
.

86

II. , , ,

RowDefinitions. RowDefinitionCollection; RowDefinition,


.
, , RowDefinition,
.
, ,
. XAML
. , , Silverlight, .
:
 XAML, , -

, << >.< >>.


, , ;
 XAML, ,
.
RowDefinitions:
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
. . .
</Grid>

RowDefinitions Grid
<Grid.RowDefinitions>, <Grid>.
<Grid.RowDefinitions> <RowDefinition>,
RowDefinition. ,
.
RowDefinition Height,
. :
 ;
 Auto ,

 * .

5.

87

< >*.

, ,
.
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
</Grid.RowDefinitions>
. . .
</Grid>

ColumnDefinitions.
ColumnDefinitionCollection
ColumnDefinition, .
ColumnDefinition Width, .
, Height RowDefinition.
<Grid>
. . .
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
. . .
</Grid>

, , :
Grid.Row="< , >"
Grid.Column="< , >"

, ,
.
<Grid>
. . .
<TextBlock Grid.Row="0" Grid.Column="0" Text=""></TextBlock>

88

II. , , ,

<TextBox Grid.Row="0" Grid.Column="1" Text="0" Width="100"


Height="22"></TextBox>
<Button Grid.Row="1" Grid.Column="1" Content=""></Button>
<TextBlock Grid.Row="2" Grid.Column="0" Text=""></TextBlock>
<TextBox Grid.Row="2" Grid.Column="1" Text="0" Width="100" Height="22"
IsReadOnly="true"></TextBox>
</Grid>


, .
Grid.RowSpan="< , >"
Grid.ColumnSpan="< ,

 >"
, ,
,
"" Grid.Row Grid.Column.
Grid.RowSpan , ; ,
Grid.Row Grid.Column, ""
. , .
Grid.ColumnSpan ,
; ,
Grid.Row Grid.Column, "" . ,
, .
<Grid>
. . .
<Button Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2"
Content=""></Button>
. . .
</Grid>

,
( 1)
.
, , "".

5.

89

""
"", , Silverlight.

.
"" StackPanel.
.
"" <StackPanel>,
, :
, , , .
<StackPanel>
<TextBlock Text=""></TextBlock>
<TextBox Text="0" Width="100" Height="22"></TextBox>
<Button Content=""></Button>
<TextBlock Text=""></TextBlock>
<TextBox Text="0" Width="100" Height="22" IsReadOnly="true"></TextBox>
</StackPanel>

StackPanel Orientation,
, .
Orientation, :
 Vertical

( );

 Horizontal

.
, StackPanel Width, Height, MinWidth,
MinHeight, MaxWidth, MaxHeight, Margin, HorizontalAlignment, VerticalAlignment
Visibility, "".
<StackPanel Width="200" Height="800" HorizontalAlignment="Right">

""
""
.
.
"" Canvas. .
"" <Canvas>, , : , , , .

90

II. , , ,

<Canvas>
<TextBlock Text=""></TextBlock>
<TextBox Text="0" Width="100" Height="22"></TextBox>
<Button Content=""></Button>
<TextBlock Text=""></TextBlock>
<TextBox Text="0" Width="100" Height="22" IsReadOnly="true"></TextBox>
</Canvas>

, Canvas Width, Height, MinWidth,


MinHeight, MaxWidth, MaxHeight, Margin, HorizontalAlignment, VerticalAlignment
Visibility, "".
<Canvas Width="400" Height="300" HorizontalAlignment="Center"
VerticalAlignment="Center">


:
Canvas.Left="< >"
Canvas.Top="< >"

,
.
(Double) .
, ,
.
<Canvas>
<TextBlock Canvas.Left="20" Canvas.Top="20" Text=""></TextBlock>
<TextBox Canvas.Left="100" Canvas.Top="20" Text="0" Width="100"
Height="22"></TextBox>
<Button Canvas.Left="100" Canvas.Top="60"
Content=""></Button>
<TextBlock Canvas.Left="20" Canvas.Top="100"
Text=""></TextBlock>
<TextBox Canvas.Left="100" Canvas.Top="100" Text="0" Width="100"
Height="22" IsReadOnly="true"></TextBox>
</Canvas>

, "",
. , XAML- , , . ,
Z- . Z- ""
""; Z-
Z-.

5.

91

Z-
:
Canvas.ZIndex="<Z->"

, Z- . , .
<TextBlock Canvas.Left="20" Canvas.Top="20" Canvas.ZIndex="2"
Text=""></TextBlock>
<TextBlock Canvas.Left="20" Canvas.Top="20" Canvas.ZIndex="1"
Text=""></TextBlock>

, . .
Z- ( ...).

,
. UserControl, , .


, .
Loaded.

.
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
txtInches.Text = "0";
}

, Text txtInches "0". Silverlight- .


, . (,
3.)
 sender, object (-

Silverlight, , ,
) ,
.

 e

RoutedEventArgs.

92

II. , , ,

; , .
Silverlight. : .
.

?
,
. ,
Silverlight . ,
.


Silverlight. "" Silverlight-.
.
-"". Silverlight ,
Silverlight 3 Tools.
, .
, Silverlight,
. , ,
.

TextBlock
C TextBlock
3. ;
, , - .
TextBlock .
, TextBlock <TextBlock>. (
.)
<TextBlock Text=""></TextBlock>

Text. ,
, .

94

II. , , ,

TextBlock Width, Height, MinWidth,


MinHeight, MaxWidth, MaxHeight, Margin, HorizontalAlignment, VerticalAlignment
Visibility, "" (. 5).
<TextBlock Text="" Width="100" Margin="5,0,5,0"></TextBlock>

TextAlignment . TextAlignment :
 Left ( );
 Center ;
 Right .
<TextBlock Text="" TextAlignment="Center"></TextBlock>

TextDecorations "" . TextDecorationCollection.


Silverlight ""
. XAML- :
<TextBlock Text="" TextDecorations="Underline"></TextBlock>

C#- :
lblInches.TextDecorations = TextDecorations.Underline;

lblInches .
.
3 , , . , TextDecorations , Underline ;
TextDecorationCollection,
.
C#- ,
TextDecorations null.
.
lblInches.TextDecorations = null;

, , TextWrapping. TextWrapping : NoWrap ( ; ) Wrap ( ).


<TextBlock Text=" ---- ."
TextWrapping="Wrap"></TextBlock>

6.

95

Padding
, .
:
< >,< >,< >,< >

.
<TextBlock Text="" Padding="20,2,20,2"></TextBlock>

, , .
FontFamily . ,
, .
Silverlight
Layout, Text, and Input / Text and Fonts
Silverlight.
<TextBlock Text="" FontFamily="Courier New"></TextBlock>
<TextBlock Text="" FontFamily="Verdana,Arial"></TextBlock>

FontFamily ,
Silverlight ,
, .
, . .
"Portable User Interface",
,
Silverlight .
FontSize
.
<TextBlock Text=" !"
FontFamily="Courier New" FontSize="36"></TextBlock>

11 .
FontStretch
. FontStretch. (
"" .
10.)
FontStretch FontStretches. :
 UltraCondensed, ExtraCondensed, Condensed SemiCondensed -

, ;
 Normal -

( );

96

II. , , ,

 SemiExpanded, Expanded, ExtraExpanded UltraExpanded -

, .
FontStretch, .
FontStretch XAML- :
<TextBlock Text="" TextStretch="Expanded"></TextBlock>

C#-:
lblInches.TextStretch = TextStretches.Expanded;

lblInches .

FontStretch
. , ,
...

FontStyle :
. FontStyle. FontStyles, : Normal
( ; ) Italic ( ). FontStyle, .
<TextBlock Text="" TextStyle="Italic"></TextBlock>
lblInches.TextStyle = TextStyles.Italic;

FontWeight "" .
FontWeight.
FontWeights Thin, ExtraLight, Light, Normal, Medium, SemiBold, Bold, ExtraBold,
Black ExtraBlack. FontWeight, "" , ""
"". Normal ( ), Bold .
<TextBlock Text="" TextWeight="Bold"></TextBlock>
lblInches.TextWeight = TextWeights.Bold;

LineHeight, .
.
Double.NaN ""; Silverlight

6.

97

. LineHeight
C#-, :
lblInches.LineHeight = Double.NaN;

, ,
C#-.
 ActualWidth (, , )


. , . .
,
.
 ActualHeight

. .
 Name , x:Name.

TextBlock

! TextBlock
,
.
, TextBlock Inlines.
InlineCollection
Inline.
5 .
<TextBlock>
<TextBlock.Inlines>
. . .
</TextBlock.Inlines>
</TextBlock>

Inline , ,
, Run LineBreak .
Run ,
. Text, FontFamily, FontSize, FontStretch, FontStyle, FonrWeight
TextDecorations, .
<Run FontFamily="Courier New" FontSize="18" Text=""></Run>

98

II. , , ,

, XAML-
<Run>.
.
<TextBlock> ( TextBlock)
<Run> ( ). , , Run, . ,
, .
<TextBlock FontSize="18">
<TextBlock.Inlines>
<Run FontFamily="Courier New" Text=""></Run>
<Run FontFamily="Arial" Text="TextBlock"></Run>
</TextBlock.Inlines>
</TextBlock>

"" Courier New,


"TextBlock" Arial. 18 .
, - : , . , , ( , )
, .
<TextBlock FontFamily="Courier New" FontSize="18">
<TextBlock.Inlines>
<Run FontSize="12" Text=""></Run>
<Run FontFamily="Arial" Text="TextBlock"></Run>
</TextBlock.Inlines>
</TextBlock>

"" Courier New


12 , "TextBlock" Arial 18 .
, Run,
. , XAML-
"TextBlock". (,
, .)
, LineBreak.
<TextBlock FontFamily="Courier New" FontSize="18">
<TextBlock.Inlines>
<Run FontSize="12" Text=""></Run>
<LineBreak></LineBreak>
<Run FontFamily="Arial" Text="TextBlock"></Run>

6.

99

</TextBlock.Inlines>
</TextBlock>

"" "TextBlock"
.

TextBox
C TextBox
3.
.
<TextBox Text="0"></TextBox>

Text , .
TextBox Width, Height, MinWidth, MinHeight,
MaxWidth, MaxHeight, Margin, HorizontalAlignment, VerticalAlignment
Visibility. ActualWidth, ActualHeight,
FontFamily, FontSize, FontStretch, FontStyle, FontWeight, Name, Padding,
TextAlignment, TextWrapping, TextBlock.
<TextBox Text="0" Width="100" Height="22" TextAlignment="0"></TextBlock>

MaxLength ,
, .
. 0,
; , , .
SelectedText , , .
, SelectedText
( ) ""; .
C#-.
if (txtTest.SelectedText == string.Empty)
{
. . .
}

, SelectedText txtTest TextBox


Empty string (
). == ,
, , , true,

100

II. , , ,

false. (. .
SelectedText txtTest
txtTest ), , ( ).
SelectionStart SelectionLength , , .
, .
, SelectionStart , ,
SelectionLength 0.
C#-.
if (txtTest.SelectionLength > 0)
{
. . .
}

> , ,
, , true,
false.
IsEnabled
. ; true ( ), false
. , C#-.
<TextBox x:Name="txtTest" IsEnabled="false"></TextBox>
. . .
txtTest.IsEnabled = true;

IsReadOnly
, true. false, , ,
( ).
AcceptsReturn ,
<Enter> (
, ). ; true ,
false ( ).
<TextBox Width="200" Height="100" TextWrapping="Wrap"
AcceptsReturn="true"></TextBox>

HorizontalScrollBarVisibility VerticalScrollBarVisibility , , , -

6.

101

.
ScrollBarVisibility :
 Auto ;
 Hidden , -


( );
 Visible ;
 Disabled , -

( ...).
<TextBox Width="200" Height="100" TextWrapping="Wrap"
AcceptsReturn="true" VerticalScrollBarVisibility="Visible"></TextBox>

, Windows-
; <Tab> , <Shift>+<Tab>
. Silverlight-.
"" Silverlight <Tab> , XAML. .
TabIndex.
.
<TextBox x:Name="txtInches" Text="0" TabIndex="0"></TextBlock>
<TextBox x:Name="txtMillimetres" Text="0" TabIndex="1"></TextBlock>

IsTabStop , false.
true ( ) .
TextBox. .
Focus() . true,
, false, .
.
txtInches.Focus();

SelectAll() .
.

102

II. , , ,

Select() .
:
Select(< >,
< >)


. .
TextBox .
.
SelectionChanged ,
.
private void txtTest_SelectionChanged(object sender, RoutedEventArgs e)
{
string s;
s = txtTest.SelectedText;
}

,
s , txtTest .
TextChanged , .
private void txtTest_TextChanged(object sender, TextChangedEventArgs e)
{
string s;
s = txtTest.Text;
}

3 , , . ; , SelectionChanged
RoutedEventArgs, TextChanged TextChangedEventArgs.
, . .
.

PasswordBox
, ,
. .

6.

103

PasswordBox.
,
.
<PasswordBox Password="password"></PasswordBox>

Password
.
PasswordChar , ""
.
<PasswordBox Password="password" PasswordChar="+"></PasswordBox>

PasswordChanged ,
;
TextChanged.
PasswordBox ActualHeight, ActualWidth,
FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxLength,
MaxWidth, MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment,
Visibility Width Focus() SelectAll().

Button
Button 3.
.
<Button Content=""></Button>

Content.
<Button Content="" Width="100" Height="25"
FontStyle="Italic" IsEnabled="false"></Button>

Content , ContentControl. ContentControl


Silverlight. ,
. ,
, 5 .
<Button Width="100" Height="100">
<Button.Content>
<TextBlock Text=" ."
TextWrapping="Wrap"></TextBlock>
</Button.Content>
</Button>

104

II. , , ,

.
<Button Width="100" Height="120">
<Button.Content>
<StackPanel>
<TextBlock Text=" ."
TextWrapping="Wrap"></TextBlock>
<CheckBox></CheckBox>
</StackPanel>
</Button.Content>
</Button>

"", ! ( <CheckBox>)!
.
Content , Silverlight ( TextBlock). , , ,
TextBlock, ContentControl. Content
ContentControl.
Button, ,
, , ClickMode :
ClickMode.

 Release -

<Enter> <> ( );
 Press <Enter>

<> ;
 Hover .
<Button Content=" !"
ClickMode="Hover"></Button>

Click .
, .
Button ActualHeight,
ActualWidth, FontFamily, FontSize, FontStretch, FontStyle, FontWeight, Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().

6.

105

CheckBox
CheckBox ( )
, .
.
<CheckBox Content=" "></CheckBox>

Content. ,
, , . . ContentControl.
<CheckBox Width="100" Height="120">
<CheckBox.Content>
<TextBlock Text=" ."
TextWrapping="Wrap"></TextBlock>
</CheckBox.Content>
</CheckBox>

, , .
. ,
, .
"" IsThreeState. true
Silverlight, ,
, , false (
).
<CheckBox Content=" " IsThreeState="true"></CheckBox>

IsChecked .
true , , false
( ), null ( IsThreeState true).
<CheckBox Content=" " IsChecked="true"></CheckBox>
. . .
if (chkOption.IsChecked)
{
. . .
}

, IsChecked C#-.
, , ,
.

106

II. , , ,

CheckBox Focus() Click.


, .
 Click .
 Checked .
 Unchecked .
 Indeterminate -

.
-
, , - . Click, ,
.
private void chkOption_Click(object sender, RoutedEventArgs e)
{
if (chkOption.IsChecked)
{
. . .
}
else
{
. . .
}
}

CheckBox ActualHeight, ActualWidth,


FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().

RadioButton
RadioButton ( )
. .
<RadioButton Content=" "></RadioButton>


Content. ,
, . . ContentControl.

6.

107

<RadioButton Width="100" Height="120">


<RadioButton.Content>
<TextBlock Text=" ."
TextWrapping="Wrap"></TextBlock>
</RadioButton.Content>
</RadioButton>

.
(
), . .
, ,
. GroupName .
<RadioButton Content=" "
GroupName="Opt"></RadioButton>
<RadioButton Content=" " GroupName="Opt"></RadioButton>

Opt .

RadioButton ActualHeight, ActualWidth,


ClickMode, FontFamily, FontSize, FontStretch, FontStyle, FontWeight, Height,
HorizontalAlignment, IsChecked, IsEnabled, IsTabStop, IsThreeState, Margin,
MaxHeight,
MaxWidth,
MinHeight,
MinWidth,
Name,
Padding,
TabIndex,
VerticalAlignment, Visibility Width, Focus() Checked,
Click, Indeterminate Unchecked.

"":
. ...

ListBox
ListBox ( ) . .
<ListBox></ListBox>

ListBox Items,
ItemCollection.

FrameworkElement,
ContentControl, , , .
ListBoxItem, .

108

II. , , ,

, , .
<ListBox>
<ListBox.Items>
<ListBoxItem Content=""></ListBoxItem>
<ListBoxItem Content=""></ListBoxItem>
<ListBoxItem Content=""></ListBoxItem>
<ListBoxItem Content=""></ListBoxItem>
</ListBox.Items>
</ListBox>

ListBoxItem Content,
.
ContentControl,
( ;
Silverlight ), .
ListBoxItem IsSelected. true , , false
. false.
<ListBoxItem Content="" IsSelected="true"></ListBoxItem>

ListBoxItem ActualHeight, ActualWidth,


FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, Margin, MaxHeight, MaxWidth, MinHeight,
MinWidth, Name, Padding, VerticalAlignment, Visibility Width.
ListBox. .
SelectedIndex . ,
-1. C#-.
if (lstTest.SelectedIndex > -1)
{
btnGo.IsEnabled = true;
}

,
.

, -
lstTest ( SelectedIndex, -1), , , btnGo ( IsEnabled true).

6.

109

SelectionChanged ,
.
ListBox ActualHeight, ActualWidth,
FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().

ComboBox
ComboBox ( ) . .

Windows . Silverlight .

ComboBox Items,
ItemCollection.

FrameworkElement. ComboBoxItem,

ListBoxItem.
<ComboBox>
<ComboBox.Items>
<ComboBoxItem Content=""></ComboBoxItem>
<ComboBoxItem Content=""></ComboBoxItem>
<ComboBoxItem Content=""></ComboBoxItem>
<ComboBoxItem Content=""></ComboBoxItem>
</ComboBox.Items>
</ComboBox>

ListBox, ComboBox SelectedIndex SelectionChanged.


MaxDropDownHeight
.
.
, , .
 DropDownOpened .
 DropDownClosed .

110

II. , , ,

ComboBox ActualHeight, ActualWidth,


FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().

Calendar
Calendar ( ) , .
System.Windows.Controls,
System.Windows.Controls.dll.
<controls:Calendar></controls:Calendar>

Visual Web Developer 2008 controls.


.

SelectedDate . !
 XAML- <>/< >/<>, ,
; -

, .
 C#-

(DateTime), 10.

<controls:Calendar SelectedDate="2009/09/08"></controls:Calendar>

8 2009 .
IsTodayHighlighted , . true ,
false . true.
SelectedDatesChanged , .
Calendar ActualHeight, ActualWidth,
FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().

6.

111

DatePicker
DatePicker ( ) , .
System.Windows.Controls,
System.Windows.Controls.dll.
<controls:DatePicker></controls:DatePicker>

Calendar, DataPicker IsTodayHighlighted


SelectedDate SelectedDatesChanged.
Text ,
, . C#-.
.
 CalendarOpened .
 CalendarClosed .
 DateValidationError ,

.
DatePicker ActualHeight, ActualWidth,
FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().

Slider
Slider ( ) . .
<Slider></Slider>

Value ,
. .
.
.
 SmallChange ,

-.
0.1.

112

II. , , ,

 LargeChange ,

.
1.
 Minimum , . 0.
 Maximum , . 10.
Orientation
. Orientation, :
 Horizontal ( );
 Vertical .
IsDirectionReversed
, . .
 false
( ).
 true .
ValueChanged .
Slider ActualHeight, ActualWidth,
FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().

ProgressBar
ProgressBar ( )
. .
<ProgressBar></ProgressBar>

Value . .
.
.

6.

113

 Minimum ,

. 0.
 Maximum ,

. 100.
, , "" . ,
, "" .
IsIndeterminate. false
, (
), true "" .
ProgressBar ActualHeight, ActualWidth,
FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, Margin, MaxHeight, MaxWidth, MinHeight,
MinWidth, Name, Padding, VerticalAlignment, Visibility Width.

ScrollViewer
ScrollViewer ( ) ,
- .
.
ScrollViewer ,
. ;
.
<ScrollViewer Width="100" Height="100"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<ScrollViewer.Content>
<TextBox Width="200" Height="200"></TextBox>
</ScrollViewer.Content>
</ScrollViewer>

.

Content ContentControl. .
, .
<ScrollViewer Width="100" Height="100"
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">

114

II. , , ,

<ScrollViewer.Content>
<StackPanel>
<TextBlock Text=" "></TextBlock>
<TextBox Width="200" Height="200"></TextBox>
</StackPanel>
</ScrollViewer.Content>
</ScrollViewer>

"",
.
HorizontalScrollBarVisibility VerticalScrollBarVisibility , , ,
.
ScrollBarVisibility :
 Auto ;
 Hidden , -

;
 Visible ;
 Disabled , -

.
HorizontalScrollBarVisibility
VerticalScrollBarVisibility Visible.

Hidden,

ScrollViewer ActualHeight, ActualWidth,


FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus.

TabControl
TabControl ( )
Windows- ; . System.Windows.Controls,
System.Windows.Controls.dll.
<controls:TabControl></controls:TabControl>

TabControl Items,

6.

115

ItemCollection.

,
FrameworkElement;
TabItem, .
<controls:TabControl Width="300" Height="100">
<controls:TabControl.Items>
<controls:TabItem Header=" ">
<TextBlock Text=" "
TextWrapping="Wrap"></TextBlock>
</controls:TabItem>
<controls:TabItem Header=" ">
<StackPanel>
<TextBlock Text=" -"></TextBlock>
<TextBox></TextBox>
</StackPanel>
</controls:TabItem>
</controls:TabControl.Items>
</controls:TabControl>

, TabItem Content, .
ContentControl,
, .
, TabItem Header,
. object (
Silverlight, ), , ( ), .
, , ,
.
TabItem ActualHeight, ActualWidth,
FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().
TabControl.
SelectedIndex,
. , -1 ( , ...).
TabStripPlacement , . Dock :

116

II. , , ,

 Top (

);
 Bottom ;
 Left ;
 Right .

Top, Bottom. Left


.

Right

SelectionChanged , .
TabControl ActualHeight, ActualWidth,
FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus().
, Silverlight . .

, , . , , , . , , Silverlight.


. .
Silverlight-
Convertor.
, ,
. , - !
Silverlight- C#
Convertor2. ( , 3.)
MainPage.xaml "", , "", 25
, . (

6.

117

.)
XAML- (, , )
<StackPanel x:Name="LayoutRoot" Orientation="Horizontal" Height="25">
</StackPanel>

:
 cboMode ,

, ;
 txtToConvert ;
 btnConvert ;
 txtConverted .

cboMode ( )
. btnConvert . txtConverted .
,
.
XAML- (,
, ):
<ComboBox x:Name="cboMode" Width="180" Margin="10,0,5,0">
<ComboBox.Items>
<ComboBoxItem Content=" "
IsSelected="true"></ComboBoxItem>
<ComboBoxItem Content=" "></ComboBoxItem>
<ComboBoxItem Content=" "></ComboBoxItem>
<ComboBoxItem Content=" "></ComboBoxItem>
</ComboBox.Items>
</ComboBox>
<TextBox x:Name="txtToConvert" Width="100" Margin="5,0,5,0"></TextBox>
<Button x:Name="btnConvert" Content="" IsEnabled="false"
Margin="5,0,5,0"></Button>
<TextBox x:Name="txtConverted" IsReadOnly="true" Width="100"
Margin="5,0,10,0"></TextBox>

. , , . . , , , ,
.
.
btnConvert Click. :
double toConvert, converted;
if (double.TryParse(txtToConvert.Text, out toConvert))

118

II. , , ,

{
if (cboMode.SelectedIndex == 0)
{
converted = toConvert * 25.4;
}
else
{
if (cboMode.SelectedIndex == 1)
{
converted = toConvert / 25.4;
}
else
{
if (cboMode.SelectedIndex == 2)
{
converted = toConvert * 0.3;
}
else
{
converted = toConvert / 0.3;
}
}
}
txtConverted.Text = converted.ToString();
}
else
{
txtConverted.Text = string.Empty;
}

txtToConvert
( double). , txtConverted
( Empty string).
.
, , cboMode . SelectedIndex cboMode,
, (0, 1, 2
3).
;
SelectedIndex , -

6.

119

, . /
, , , .
txtConverted,
ToString().
.
"" , btnConvert, - txtToConvert.
txtToConvert TextChanged:
if (txtToConvert.Text == string.Empty)
{
btnConvert.IsEnabled = false;
}
else
{
btnConvert.IsEnabled = true;
}

, !
txtToConvert , , btnConvert
.
, . .

?
, Silverlight
. , Silverlight ...
! , . - .



Silverlight,
. .
Silverlight -.
!
,
( ). , !


Silverlight
. JPEG.
Image. image.jpg , .
! , , . ( 8.) Solution
Explorer (. . 3.2) "" ( , ) Existing Item Add
. Add Existing
Item, , ,
. Solution Explorer

7.

121

, , , Visual Web Developer 2008


.
.

Image
Image. .
<Image Source="image.jpg"></Image>

Image, ,
Source, , . XAML- .

Image Silverlight
JPEG PNG, . .NET Framework Class Library for Silverlight /
System.Windows.Media.Imaging Namespace / BitmapImage Class Silverlight.

, . -
Source Image.
Silverlight ,
21.

Image Stretch,
, ,
, . Stretch :
 None , -

;
 Fill , -

, ;
 Uniform -

,
( );

122

II. , , ,

 UniformToFill

, ;
.
<Image Source="image.jpg" Stretch="None"></Image>

Image .
 ImageOpened

.
 ImageFailed ,

(,
Silverlight ).
Image ActualHeight, ActualWidth, Height,
HorizontalAlignment, Margin, MaxHeight, MaxWidth, MinHeight, MinWidth, Name,
VerticalAlignment, Visibility Width.
<Image Source="image.jpg" Width="480" Height="640"></Image>


, .
. ? .
, Source Image XAML-
, . ImageSource,
- BitmapImage. ,
.
XAML-
Source Image, Silverlight,
XAML,
ImageSource. C#- .
, , Loaded . <UserControl>,
:
<UserControl . . . Loaded="UserControl_Loaded">

<Image>, , Source , , imgSample. MainPage.xaml.cs


Visual Web Developer 2008 ""
UserControl_Loaded. .

7.

123

, , Uri,
( -) .
Uri, .
Uri uFileName;

.
uFileName = new Uri("image.jpg", UriKind.Relative);

new ,
.
.
3 ,
, , , , . ,
, new, .
.
. UriKind ,
. UriKind.Relative UriKind.RelativeOrAbsolute. ( UriKind 21.)
, Uri, , .
BitmapImage,
.
, .
System.Windows.Media.Imaging.BitmapImage bimFile;

BitmapImage System.Windows.Media.
Imaging, . , .
( ,
. 4.)
.
bimFile = new System.Windows.Media.Imaging.BitmapImage(uFileName);

BitmapImage. Uri, .

, . .

124

II. , , ,

Source imgSample.
imgSample.Source = bimFile;

! .
, Silverlight
. ,
.


Silverlight- , .
- - ,
.
, , Media.
media
( media.mp3).
, .
, .
! Solution
Explorer , ,
. Visual Web Developer 2008
Properties; - , <F4>, . Build Action
Resource. , 8.

MediaElement
MediaElement.
.
<MediaElement Source="media.mp3"></MediaElement>

MediaElement, ,
Source, ,
.
XAML- .

MediaElement Silverlight MP3, MP4


Windows Media. Graphic, Animation, and

7.

125

Media / Audio and Video / Supported Media Formats, Protocols, and Log Fields
Silverlight.

MediaElement ActualHeight, ActualWidth,


Height, HorizontalAlignment, Margin, MaxHeight, MaxWidth, MinHeight, MinWidth,
Name, Stretch, VerticalAlignment, Visibility Width.
<MediaElement Source="media.mp3" Stretch="None" Width="400"
Height="300"></MediaElement>

AutoPlay ,
. true
, false . true.
Volume 0 1. 0.5.
Balance -1 ( ) 1 ( ). 0 ( ).
IsMuted . true ,
false . false.
CurrentState , . MediaElementState
:
 Closed ( );
 Opening ;
 Individualizing , -

;
 AcquiringLicense -

(, , );
 Buffering -

;
 Playing ;
 Paused ;
 Stopped

.

C#-.

126

II. , , ,

Position . TimeSpan ,

.
10.
MediaElement
, .
.
 Play() .
 Pause() . -

Play().
 Stop() .

, .
 MediaOpened .
 MediaFailed

.
 MediaEnded .
 CurrentStateChanged
CurrentState (

).

Image MediaElement ( ) , , .
Silverlight.


, MediaElement
. ,
Image.
Source MediaElement XAML- , .
Uri. XAML- Source MediaElement,
Silverlight, XAML,
Uri.
C Uri , . , .

7.

127

, , ,
, Loaded .
MediaElement melSample.
Uri, (
-) ,
.
Uri uFileName;
uFileName = new Uri("media.mp3", UriKind.Relative);

Source melSample.
melSample.Source = uFileName;

?
Silverlight, .
- .
- .
?


,
. , ( ).
.
, ...
!


4 , Visual Web Developer 2008
. (
Windows Silverlight) (
).
? -, ,
MSIL, Silverlight. -, , . -...
"-" ! Silverlight
. , , . , , , .
, Image
image.jpg, Media media.
, !

8.

129

, , . - .
13, , . ,
!


Visual Web Developer 2008 . .
, , .
 Add Existing Item Project.
 ""
Solution Explorer (. . 3.2) Existing Item
Add . ("" , , .)
 <Shift>+<Alt>+<A>.
Add Existing Item, Windows.
.

,
.

Solution
Explorer, "". , ,
.
, - .
Rename Solution Explorer,
<F2>. , ;
<Enter> <Esc> .
,
Exclude From Project .
.

130

II. , , ,

Delete - Solution Explorer <Del>,


, ( ,
) .



, .
. ,
.
, , . ,
, .

, .
.
, (
, .).

( ).
.
, - , ,
, .
, Visual Web Developer 2008 . ,
; , . , , Properties,
.
Properties (. 8.1) . Solution Explorer .
- , Properties
Window View <F4>.

8.

131

. 8.1. Properties

, Properties , , .
Build Action Copy to Output.
Build Action , Solution Explorer.
, : Resource (
) None ( ).
Copy to Output . , .
 Do not copy , -

.
 Copy always ,

( Debug
Release, bin, , ,
).
 Copy if newer , -

, , ,
.
,
, .
.

132

II. , , ,


XAML- C#- ,
Silverlight .
, . . . , , .
Silverlight ,
. .
 Web- Silverlight

, , Web.
 Web- Silverlight Web-

, Web- Web- , , , Web.


, .
Silverlight , , .



- ,
. Silverlight, ,
, .
,
New Folder Add ""
Solution Explorer. ;
<Enter>
.
. New Folder Add, , .
,
, . . . 8.2

8.

133

medias sounds; media.mp3,


.

. 8.2. Solution Explorer

,
; , .
, . 8.2 Visual Web Developer 2008 medias, sounds, media.mp3.
. , .
! , , . , , .
, Web Silverlight-.
.
,
, Web-;
(, !).
. , "" , , Web-,
Silverlight-.
, . 8.2 media.mp3
:
medias/sounds/media.mp3

- , ,
, Visual Web Developer 2008
, . ,
.
, ...

134

II. , , ,

?
. ,
Silverlight...
, Silverlight
- C#.
, . !

III

C#
9.

C#

10.

C#

11.

12.


C#
C# .
. .
C#.
( - XAML, -,
, ), .
.
C#. ,
.

, , ,

, C# . ,
. , ; , .
:
sgMillimetres = sgInches * 25.4;

sgInches , 25.4 sgMillimetres.


3.
sgInches sgMillimetres. -

138

III. C#

, -
, .
.
( , , ).
,
.
, 25.4
, . (,
.) .
"Silverlight", 435, true
.
*. C#, , , , ( , ,
10). * sgInches 25.4 ...
... sgMillimetres
=. , , , .
:
sgMetres = sgInches * 25.4 / 1000;

: *
/. .
1. sgInches 25.4.
2. 1000.
3. sgMetres.
, .
, . ( .)
:
x = x + 2;

9. C#

139

C C# , . x 2,
x. .
, , . ,
double
sgInches, (double).
double sgInches;

class , if . .
, C#.
 .
: , , , . . .
 (;).
, , .
,
sgMetres = sgInches * 25.4 / 1000;

:
sgMetres = sgInches * 25.4 /
1000;

:
sgMetres =
sgInches *
25.4 /
1000;

, , ...
C# .
, , .


C# . , :

140

III. C#

, , ,
- . ,
.

C#, Silverlight
, Silverlight , ,
C#. , : ,
, .
, .
"" : Silverlight, "" . ,
, .
Silverlight
C#. , string () C#
String Silverlight, double ( )
Double, bool Boolean.
Visual Web Developer 2008 , C#, , Silverlight. Silverlight.
? C#,
Silverlight. :
bool bFlag;
Boolean bFlag;

bFlag ,
C# bool,
Silverlight Boolean. , .

( ) , , , . , :
"Silverlight 3"
"1234567"
" ."

9. C#

141

string. Silverlight String.


string sValue;

( ), . , 2 ,
.
, .
, .
.
. Silverlight
Unicode. 65 535 . Silverlight , .
, ,
, .
, C#, . 9.1.
9.1. , C#

Unicode

\"

0x0022

\'

0x0027

\\

0x005c

\r

0x000d

\n

0x000a

\t

0x0009

\xFFFF

Unicode ( FFFF)

, ,
:
"\"Silverlight 3\" -"

"", .
sValue = "";

142

III. C#

Empty String,
.
sValue = String.Empty;

C# , . : 45,
2563446, -74376.
, C# .
. 9.2.
9.2. C#

C#

Silverlight

int

Int32

2 147 483 648 2 147 483 647

uint

UInt32

0 4 294 967 295

short

Int16

32 768 32 767

ushort

UInt16

0 65 535

long

Int64

9 223 372 036 854 775 808


9 223 372 036 854 775 807

ulong

UInt64

0 18 446 744 073 709 551 615

int ( ) uint ( ). ,
, short (
) ushort ( ). "" , , .
, ,
. 0
1 A F
C# 0x. :
0x5f8c.


C# , .

9. C#

143

, . : 25.4, 0.63465, -234.8.


<>E<>. ,
( ):
5
23
1E-5 (10 ), 8.546E23 (8,54610 ).
, C# .
. 9.3.
9.3. C#

C#

Silverlight

double

Double

510324 1,710308

float

Single

1,51045 3,41038

decimal

Decimal

11028 7,91028

double ( ), . .
Silverlight. , , , float ( ). decimal
( )
, .

,
"" "",
true false.
bool.
Silverlight Boolean.

-
Unicode ( . , ).
,

144

III. C#

. . : 't', '\\', '\u0058'.


char.
Silverlight Char.


Silverlight .
, .
. ,
. ,
x 4,
4.
x y,
y x.
, , - .
,
"".
Silverlight
10.


,

. ? , .



Silverlight. - , , , , ,
.
,
.
 int long, float, double decimal.
 uint long, ulong, float, double decimal.
 short int, long, float, double decimal.

9. C#

145

 ushort int, uint, long, ulong, float, double decimal.


 long float, double decimal.
 ulong float, double decimal.
 float double.
 char ushort, int, uint, long, ulong, float, double decimal.

, .
, ,
, Visual Web Developer 2008.
, , , .
, , ,
.


,
.

.
( C# Silverlight),
, .
double d = 1234.567;
int c;
= (int)d;

double int.
, . . , , .

, ,
. .

,
.
 int short, ushort, uint, ulong char.
 uint short, ushort, ulong char.
 short ushort, uint, ulong char.

146

III. C#

 ushort short char.


 long short, ushort, int, uint, ulong char.
 ulong short, ushort, int, uint, long char.
 double short, ushort, int, uint, long, ulong, char, float decimal.
 float short, ushort, int, uint, long, ulong, char decimal.
 decimal short, ushort, int, uint, long, ulong, char, float double.
 char short.

ToString(),
,
.
TryParse() .
10.

. , ,
, ,
- .


, (_), , . , sgInches _decodedValue
, 2number .
C# , .
, decodedvalue DecodedValue .
. -, "", , . , , , decodedValue . , ,
decodedFromStringToDoubleValue - .
-, ()
, , decodedValue, dbMillimetres. , Silverlight
() , -

9. C#

147

()
.
-, - , . , iCount ( int), sInches ( string), dcPrice (
decimal). , ,
.
, ,
- . , i, s, t2 .

.

, . , C#,
, Silverlight, , , . ;,
.
string sInches;
double sgInches;
int i;

sInches , sgInches
i.
.
- , =:
int i = 2;

-, .
Silverlight , ""?
-, C# Silverlight
. ,
. !

148

III. C#


. .

,
. ,
Silverlight.

-
, ,
. (
10.)

,

, . , , 6.
private void btnConvert_Click(object sender, RoutedEventArgs e)
{
. . .
}

, ,
Silverlight , .
, , .
, sender
object e RoutedEventArgs.
, ,
. .

, . .

9. C#

149


. ,
C#, . 9.4.
9.4.

++

( )

--

( )

: .
;
, .
, .
:
++r;

r , . :
s = ++r;

s.
,
. , , . :
r = 3;
s = ++r 1;


r , (4)
r, () . s 3.

150

III. C#

,
, . :
r = 3;
s = r++ 1;

r , s 2.
r (4) .
.
,
. 9.4 ,
. :
x = x + t;
l = r * 3.14;
f = -e / 2;

, - .
, .


, , +
. , :
s1 = "Microsoft";
s2 = "Silverlight";
s3 = "3";
s = s1 + " " + s2 + " " + s3;

s "Microsoft Silverlight 3".


= . :
a = 2;

, C#
.
:

9. C#

151

a = a + b;
a += b;

. +=.
, C#, . 9.5.
9.5.

a += b;

a = a + b;

a -= b;

a = a b;

a *= b;

a = a * b;

a /= b;

a = a / b;

a %= b;

a = a % b;

" + ".



. , true,
false. :
a1 = 2 < 3;
a2 = -4 > 0;
a3 = r < t;

a1 true (2 3), a2 false (-4 ), a3


r t.
C# . 9.6.
9.6.

<

>

==

152

III. C#
9.6 ()

<=

>=

!=


.
. 9.7. . 9.8 9.9 .
9.7.

( )

&&

( )

||

( )

9.8.
1

&& ()

|| ()

true

true

true

true

true

false

false

true

false

true

false

true

false

false

false

false

9.9.

! ()

true

false

false

true

:
a = (b > 0) && (c + 1 != d);
flag = !(status = 0);

9. C#

153


?
. :
<> ? < true> : < false>

true, true.
false.
s = (i > 2) ? " " : " ";

, .


C# . :
a = b + c 10;

b
c, 10. , .
:
a = b + c * 10;

c 10,
b. "
" .
? , , , .
, , .
, .
. 9.10
.
9.10. ( )

<>++
<>--

154

III. C#
9.10 ()

++<>
--<>
- !
(<>)

, , ,

* / %

, ,

+ -

< > <= >= = !=

= <>=

&&

||

.
,
.

, : , .
( ).
, ? . .
a = (b + c) * 10;

b
c, 10.
, , .
:
a = ((b + c) * 10 d) / 2 + 9;

:
1. b c.
2. 10.
3. d .

9. C#

155

4. 2.
5. 9 .
:
a = b + c * 10 d / 2 + 9;

:
1. c 10.
2. d 2.
3. b c 10.
4. d 2.
5. 9 .
, ?


,
.
, .

C# ,
. ,
.
{
b = "12";
c = a b;
}

,
.
C#-
. 3.



-
. .

156

III. C#

:
if (<>)
< true>
else
< false>

if else.
" if-else".
,
Silverlight , .
. true, true. false,
false.

.
if (x
{
a =
b =
}
else
{
a =
b =
}

== 1)
"";
1;

" ";
22222;

x
f h .
if ((x == 1) && (y > 10))
{
f = 3;
}
else
{
f = 33;
}

, true
, x 1 y 10.
, "" , true, , .

9. C#

157

if (<>)
< true>

:
if ((x == 1) && (y > 10))
{
f = 3;
}


, . :
switch (< >) {
case < 1> :
< 1>
break;
[case < 2> :
< 2>
break;]
<... case>
[default :
<, >]
}

switch, case default


break, . " switch-case".

1, 2 . . , ,
( 1, 2 . .).
, ,
default (, , ).
:
switch (a) {
case 1 :
out = "";
break;
case 2 :
out = "";
break;
case 3 :
out = "";
break;

158

III. C#

default :
out = " ";
}

, a 1, out "", 2 "", 3 "".


a - , out
" ".
break, Silverlight
, , ,
. ,
. ,
1 1, break, 2.
break :
switch (a) {
case 1 :
out = "";
case 2 :
out = "";
case 3 :
out = "";
default :
out = " ";
}

, . out " ".

,
. .
C# . .


, -
. ,
.

9. C#

159

:
for (< >; <>; <>)
< >

for. " for".


.
, ,
( 1).
, , .

. , .
, . true, ,
, .
,
. ( ). , , . ., false.
:
for (int i = 1; i < 11; i++)
{
a += 3;
b = i * 2 + 1;
}

10 . i
1 . ,
11, .

. i
1 10, .
:
for (int i = 10; i > 0; i--)
{
a += 3;
b = i * 2 + 1;
}

160

III. C#

. 10.
10 , i 0;
10
1.
for (int i = 2; i < 21; i += 2)
{
b = i * 2 + 1;
}

2, 21,
, , 10 . , 2 2, 4, 6... 20.
"" for .
" " .


,
, , .
, ,
.
, .
:
do
< >
while (<>);

do while.
" do-while".
:
do {
a = a * i + 2;
i = ++i;
} while (a < 100);

:
var a = 0, i = 1;
do {
a = a * i + 2;

9. C#

161

i = ++i;
} while (i < 20);

, . , ,
.


,
. , () , .
while (<>)
< >

while.
" while" ( "
do-while"!).
:
while (a < 100) {
a = a * i + 2;
i = ++i;
}


. C# break continue.
break .
while (a < 100) {
a = a * i + 2;
if (a > 50)
{
break;
}
++i;
}

, a 50.
continue , . .
, ,

162

III. C#

: , . .
while (a < 100) {
i = ++i;
if (i > 9 && i < 11)
{
continue;
}
a = a * i + 2;
}

a i 10
20.



, . . .
goto.
, . :
< >:

. , .
goto :
goto < >;

, Silverlight
, .
if (x > 100)
{
goto TooBig;
}
. . .
TooBig:
. . .

, x 100,
TooBig.

9. C#

163

goto (. ).
:
goto < case, >;

:
switch (a) {
case 1 :
out = " ";
break;
case 2 :
goto case 1;
case 3 :
out = "";
break;
}

, a 2, case 1.

, . .
. .
, , .
, .
.
, , .

,
. .

:
< >[] < > =
new < >[< >];

164

III. C#

< >[] < > =


{< , >};

,
.

;
, .
Array.
7
new.
string[] sPlatforms = new string[4];

sPlatforms .
string[] sPlatforms = {"HTML+CSS+JavaScript", "Flash", "Java",
"Silverlight"};

,
.
,
.
s = sPlatforms[2];

s
sPlatforms 2 ( ) "Java".
sPlatforms[3] = "Silverlight 3";

sPlatforms 3 ( ) .
C# (
).
.
int[,] iMatrix = new int[4, 4];

iMatrix
44. ,
, ,
.

9. C#

165

double[, ,] dCube = new double[3, 3, 3];

(""). ,
. .
,
.
iMatrix[1, 2] = 4;
dValue = dCube[2, 0, 1];

, . :
< >[][] < > =
new < >[< >][];

:
int[][] iMatrix2 = new int[2][];
iMatrix2[0] = new int[2];
iMatrix2[1] = new int[4];
iMatrix2[2] = new int[5];

,
.
"" , "" , "" ,
.
iMatrix2[1][2] = 2;
iMatrix2[2][4] = 7;


, C#.
, , .
"" - .
:
foreach (< > < > in <>)
< >

, foreach in.
" foreach-in".

166

III. C#

, . .
.
, . .
.
, .
; .
string output = "";
foreach (string str in sPlatforms)
{
output += str + "\r\n";
}

sPlatforms
output, .
int s = 0;
foreach (int i in iMatrix)
{
s += i;
}

s iMatrix. : , !

, C#- - . C#, .
,
.
ActionScript
: // /*...*/. :
//
a = b + c; //

, ,
.

9. C#

167

/*...*/ :
/*


*/
a = b + c;

, , ( ), . .

?
C#.
, ?
C# :
. . C#: , . .
!

10

C#
C#. , .
, , . , , .
!

C#. ,
: . , , ...
.
4. ,
, ,
. Silverlight.


2. ,
.
, ,
, .
,
. , -, .

10. C#

169


.
.

, .
9 , .
- ,
. , , , .
,
.

, , ,
, , .
. .
, , , , . , , -
.

, -
. , .
, , .
 , . -

.
 Get-, .
 Set-, -

170

III. C#

, , ( ).
get- set- .
, get-
. , , ,
() .
get- ,
. , , ,
,
.
Set- , .
,
: ,
- .

: -
!
, IsEnabled
TextBox ( ), Silverlight , , , .
, get-, set. , , set-.
; get-
. , String ( ) Length,
;
get-.
get-.
. , .

, , Web-, .

10. C#

171

, . , , . . Silverlight.
,
, . .
, , ,
, , . ,
,
.
. , ,
Microsoft SDK for Visual Studio 2008.


9 ,
. , true
false, .
C# -
, . ,
,
.
, - . , , ,
.


, : , , . .
, .


, , , .
, , , - .
, , , , . , ,
.

172

III. C#

-
, , , ,
. ( , . . .)
: ,
.
... , . .

. .


Silverlight. .
2, .
-, -, : , , ( ), , .
, .
-
, , .
Silverlight .


:
; ,
. C# .


, 7, new. :
new < >([< ,
 >]);

10. C#

173

new .
;
, .
new (, ,
), .
,
(. . , , ).
SomeClass sc;
OtherClass oc;
sc = new SomeClass();
oc = new OtherClass(10, 4.5);


, . ( ,
. . 4.)
sc = new OuterNameSpace.InnerNameSpace.SomeClass();

, . . , "", , "" ,
.
sc = new OuterNameSpace.InnerNameSpace.OuterClass.InnerClass();


9 , Silverlight , ,
, . .
. .
Silverlight .
.
, .
, , , .
, ,
, .
, 9 . ,
, . .
Array.

174

III. C#



. (. . , ),
.
sc.SomeProperty = 20;
txtMillimetres.Text = "100";
sInches = txtInches.Text;

,
(, ).
if (txtInches.Text == String.Empty)

Empty String, , Text


txtInches.
, , .
,
this; Silverlight,
. .
this.SomeProperty = 40;
SomeProperty = 40;


SomeProperty , .
, , , .
, , (
; , ), , . ,
.
sc.SomeMethod(2, 56, "");
txtInches.Focus();

. ,
, .
m = sc.OtherMethod(22);
n = (sc.OtherMethod(44) + 3) / 0.5;

, -
, .

10. C#

175

, -, ( ), -,
out.
result1 = sc.ThirdMethod(65.2, out result2);

, ,
result1, ,
result2.
.
XAML- Visual Web Developer 2008;
, . C#-,
.
private void btnConvert_Click(object sender, RoutedEventArgs e)
{
}

, , - Visual Web Developer 2008.


. (
, , ,
), , ,
. +.
btnConvert.Click = btnConvert.Click + btnConvert_Click;

, .
:
btnConvert.Click += btnConvert_Click;

"" , ,

.
btnConvert.Click = btnConvert.Click btnConvert_Click;
btnConvert.Click -= btnConvert_Click;

, ,
(, ), ,
.
a = SomeClass.SOME_NAMED_CONSTANT;

, .

176

III. C#



9 C#,
. , , , .
is true, ,
, , , . , false.
if (txtInches is TextBox)
{
. . .
}

, . . txtInches
TextBox ( ).
if ("Silveright" is Double)
{
. . .
}

"Silverlight"
.
as
, , (), .
, ,
; null.
FrameworkElement felControl;
felControl = txtInches as FrameworkElement;

felControl txtInches,
FrameworkElement. ( FrameworkElement , .)
double d;
d ="Silverlight" as Double;

d null.
9
(< >)< >. ,
?

10. C#

177

, (< >)< >


. ( 12.) as,
, null. , ,
...

null
null. ?
, .
, .
FrameworkElement felControl;
felControl = txtInches as FrameworkElement;
if (felControl != null)
. . .

null (
). ,
.
felControl = null;


, , .
?
, . Silverlight
, - .
, - , . ,
, . ( , ), . Silverlight.

Silverlight

Silverlight, -

178

III. C#

.
Silverlight.

Object
Object Silverlight;
, , , .
Object Silverlight object C#.

String
String Silverlight . ,
,
Silverlight.
Chars , .
(char).
string str = "Silverlight";
char ch;
ch = str.Chars(2);

ch 'l'
"Silverlight". ( .)
Length .
IndexOf()
. :
IndexOf(< >
[, < , >])

(char) , . , ; ,
.
string str = "Silverlight";
int i1, i2;
i1 = str.IndexOf('l', 4);
i2 = str.IndexOf("ver");

i1 6 (
'l' "Silverlight"), i2 3.

10. C#

179

String IndexOf, . , , , . .

LastIndexOf() IndexOf() ,
, .
string str = "Silverlight";
int i;
i1 = str.LastIndexOf('l');

i 6.
Substring() ,
.
Substring(< >[, < >])

,
; , . .
string str = "Silverlight", s;
s = str.Substring(6, 3);

s "lig".
String Substring, . , .

ToLower() ToUpper() , .
, String . Silverlight.

Math
Math .
E PI
e .

180

III. C#

Math . 10.1.
10.1. Math

Abs(<>)

Acos(<>)

Asin(<>)

Atan(<>)

Ceiling(<>)

Cos(<>)

Exp(<>)

Floor(<>)

Log(<>)

Log10(<>)

Max(< 1>, < 2>)

Min(< 1>, < 2>)

Pow(<>, <>)

Round(<>)

Sign(<>)

1,
, 0, , 1,

Sin(<>)

Sqrt(<>)

Tan(<>)


Silverlight,
. .

10. C#

181


, 3,
, class. , , , .
[< , >] class < >
[: < - ,
 >]
{
< >
}

,
( . 9). ,
Silverlight , ; ,
SomeClass someclass Silverlight .
-.
, Object. , ;
- . (
.)

-. .

C#, . .
 public

, ( ). , ,
, .
 internal

( ). .
 private

, ( ). .
 sealed -

. Silverlight .

182

III. C#

 abstract , . .

- ( ). , "" .
 static (

).
 partial .

sealed
abstract (, , ).
(, , ).

, ,
Silverlight-.

,
, .
abstract class SomeClass

SomeClass,
, .
-, Object.
public class OtherClass: ParentClass, ISomeInterface

OtherClass,
ParentClass ISomeInterface.


:
[< , >] < > < >
[= < >];

C#, , ,
Silverlight.
, , ,
.
f ( . field ) .

10. C#

183

.
 public ,
, (
).
 protected -
( ).
 internal , ( ).
 protected internal , ( ).
 private ,
( ).
 static .
 readonly .
.
, . (
.)
, , ,
, .
( public)
. .
protected string fName;

fName.
static public int fCounter = 0;

( !) fCounter, 0.


:
[< , >]
< > < >
([< , >])
{
< >
}

184

III. C#

C#,
, , Silverlight.
,
void.

, .

. :
< > < ,
 >

. , .
, . .
-
, out.
.
 public ,

, (
).
 protected -

( ).
 internal , -

( ).
 protected internal -

, ( ).
 private ,

( ).
 static .
 overide ,

- ( ).
 virtual - (-

).
 abstract -

- ( ).

10. C#

185

 sealed -.

, .


return. :
return < >;

, , ,
this. ,
, , .


-. :
base.< >

base -.
Silverlight ,
, . -"" .
:
public int Increment(int iPar)
{
return iPar + 1;
}
. . .
i = sc.Increment(1);

, , . sc,
1, i 2.
public void Increment2(out int iPar)
{
iPar += 1;
}

186

III. C#

. . .
i = 1;
sc.Increment2(out i);

,

. i 1,
sc, ,
2.
protected virtual string SomeMethod()

-.
protected override string SomeMethod()
{
. . .
base.SomeMethod();
. . .
}

- .
-.


Silverlight . .
. . ,
.
.
 , .
 ( -

).
 .
public SomeClass()
{
this.SomeProperty = 10;
}

, SomeProperty
SomeClass 10. ,
this.

10. C#

187

public SomeClass(int iSP)


{
this.SomeProperty = iSP;
}

, .
( );
. , SomeClass ,
.

, . .

.
.
.
 , .
 .
 .
 .
static SomeClass()
{
SomeStaticProperty = 228;
}


SomeClass 228. ,
.
SomeStaticProperty


:
[< , >] < >
< >
{
[get
{
< get->
}]

188

III. C#

[set
{
< set->
}]
}

C#, , , Silverlight. , .
.
 public , , ( ).
 protected ( ).
 internal , ( ).
 protected internal -, (
).
 private , ( ).
 static .

Get- ,
. Set- .
set- value. Silverlight,
set-.
private int fSomeProperty;
public int SomeProperty
{
get
{
return this.fSomeProperty;
}
set
{
this.fSomeProperty = value;
}
}

10. C#

189

set-,
. get-,
.
C# . :
[< , >] < >
< > { get; set; }

, Visual Web Developer 2008


, get, , set-,
.
public int SomeProperty { get; set; }



const:
[< , >] const < >
< > = < >;

C#, ,
, Silverlight.
, .
() .
.
,
, .

.
 public , -

, ( ).
 protected -

( ).
 internal , -

( ).
 protected internal -

-, (
).

190

III. C#

 private , -

( ).
public const string PLATFORM_NAME = "Silverlight";
public const int PLATFORM_VERSION = 3;

: PLATFORM_NAME
PLATFORM_VERSION.

"" .
, , , ,
. , .
 , .


( ).
 , -

.
 -

.
, , , "" . , Silverlight ,
.


,
.
SomeStructure st;
st.SomeProperty1 = 2;
st.SomeProperty2 = "eee";
st.SomeMethod();

st SomeStructure,
SomeProperty1 SomeProperty2
SomeMethod. , , , .

10. C#

191

, new.
SomeStructure st;
st = new SomeStructure(2, "eee");

, .

Silverlight
Silverlight,
.
Silverlight.

Int16, Int32, Int64, UInt16, UInt32 UInt64


, . 9.2.
MaxValue MinValue , , , .
TryParse() .
TryParse(< >, out < >)

, , , .
TryParse() true, , false .
ToString() , .

Double Single
double float
(. . 9.3).
,
. 10.2.
IsInfinity(),
IsPositiveInfinity() true,
, Not A Number, + , false
.
IsNaN(), IsNegativeInfinity()

192

III. C#
10.2. Double Single

Epsilon

MaxValue

MinValue

NaN

Not A Number ""

NegativeInfinity

PositiveInfinity

TryParse()
.
TryParse(< >,
out < >)

, , , .
TryParse() true, , false .
ToString() , .

Decimal
decimal
(. . 9.3).
, Silverlight.
.
MaxValue MinValue , , , .
TryParse() .
TryParse(< >,
out < >)

, , , .

10. C#

193

TryParse() true, , false .

ToString() , .

DateTime
DateTime .

new DateTime(<>, < >, <>
[, <>, <>, <>[, <>]])

, . .
DateTime dt;
dt = new DateTime(2009, 10, 27, 23, 0, 0);

dt ,
27 2009 23:00:00.
DateTime ,
. 10.3.
, .
10.3. DateTime

Date

DateTime,

Day

DayOfWeek

, DayOfWeek . DayOfWeek Sunday (), Monday (), Tuesday (),


Wednesday (), Thursday (), Friday () Saturday
()

DayOfYear

Hour

Millisecond

Minute

Month

Now

DateTime,
.

194

III. C#
10.3 ()

Second

TimeOfDay

TimeSpan, ( TimeSpan )

Today

DateTime, .

Year

DateTime ,
(. 10.4).
10.4. DateTime

Add(<>)


, TimeSpan

AddDays(<>)

AddHours(<>)

AddMilliseconds(<>)

AddMinutes(<>)

AddMonths(<>)

AddSeconds(<>)

AddYears(<>)

10. C#

195

DateTime dt;
dt = DateTime.Now;
dt.AddYears(2);
dt.AddMonth(6);

dt . , C#.

TimeSpan
TimeSpan
.

new TimeSpan([<>, ]<>, <>, <>[, <>])

, . .
TimeSpan ts;
ts = new TimeSpan(2, 20, 0);

ts 2 20 .
TimeSpan ,
. 10.5. , .
10.5. TimeSpan

Days

Hours

Milliseconds

Minutes

Seconds

TotalDays

TotalHours

TotalMilliseconds

TotalMinutes

TotalSeconds

196

III. C#

TimeSpan , Silverlight.


, .
struct.
[< , >] struct < >
[: < , >]
{
< >
}
,
, .

public struct SomeStructure


{
public short SomeProperty1 { get; set; }
public string SomeProperty2 [ get; set; }
public void SomeMethod()
{
. . .
}
}

.
- , -.
, , ,
, . , .
,
, . , ; get- set- .
, . () ,
, .
() .

10. C#

197

, . , struct.
[< , >]
interface < >
[: < -, >]
{
< >
}

,
. I ( .
interface). .

.
public interface ISomeInterface
{
double SomeInterfaceMethod(double db);
int SomeProperty { get; set; }
}

ISomeInterface SomeInterfaceMethod,

, SomeProperty . , .
class SomeClass: ISomeInterface
{
public double SomeInterfaceMethod(double db)
{
. . .
}
public int SomeProperty
{
get
{
. . .
}
set
{
. . .
}
}

198

III. C#

. . .
}
class OtherClass: ISomeInterface
{
public double SomeInterfaceMethod(double db)
{
. . .
}
public int SomeProperty
{
get
{
. . .
}
set
{
. . .
}
}
. . .
}

SomeClass OtherClass, . .
SomeClass sc = new SomeClass();
OtherClass oc = new OtherClass();
double d11 = sc.SomeInterfaceMethod(4.2);
double d12 = oc.SomeInterfaceMethod(0.74);

... -.
ISomeInterface isi1 = new SomeClass();
ISomeInterface isi2 = new OtherClass();
double dl1 = isi1.SomeInterfaceMethod(4.2);
double d12 = isi2.SomeInterfaceMethod(0.74);

. ,
, . , ,
, . .
. .
Silverlight , .

10. C#

199

, .
Silverlight.

, .
,
();
.
enum.
:
[< , >]
enum < >
{< , >};
,
, .

:
public enum Platforms {HTMLCSSJavaScript, Flash, Java, Silveright};

,
: ,
.
Platforms pl;
pl = Platforms.Flash;
. . .
if (plPlatformName == Platforms.Silverlight)
. . .

, - .
, .

?
! Silverlight!.. , , , , , , , ... ?..
. . -
. -, !
, ...

11

: , , .
Silverlight . Silverlight, ,
. ( Silverlight,
.)
. .


3,
Silverlight-. ,
( );
, ( , ),
, ""
.
9 .
.
 , ,

. , ; .

 , .

11.

201

, .

Silverlight- , ,
, . , ( 13) , ,
.


, .
, Silverlight .
, , - , , , (), , (
).
.

"" . !
? ,
. .
Silverlight , , , .
( , , ), .

List
List. , "" . .

List
, List,
. :
List<< >> < >;

202

III. C#

,
< >.
List, .
new. :
new List<< >>()

.
List<string> lstCol;
lstCol = new List<string>();

lstCol, ( String).


List Count, . .



,
. (, ,
).
Add . .
lstCol.Add("HTML + CSS + JavaScript");
lstCol.Add("Flash");
lstCol.Add("Silverlight");


-.
Insert .
:
Insert(< >, < >)

(),
. , -

11.

203

. . Insert .
lstCol.Insert(2, "Java");

Java!
Remove , . true, ,
false (,
).
lstCol.Remove("Flash");

Silverlight.
RemoveAt ,
. .
lstCol.RemoveAt(0);

...
Clear , .
.
lstCol.Clear();


, Item.
.
string st;
st = lstCol.Item[3];

st
"Silverlight".
Item List . , .
string st;
st = lstCol[3];

Item ,
.
lstCol[3] = "Silverlight 3";

lstCol
"Silverlight" "Silverlight 3".

204

III. C#


?
List .
Contains , ,
. true,
, false .
bool flag1, flag2;
flag1 = lstCol.Contains("Flash");
flag2 = lstCol.Contains("Delphi");

flag1 true
( lstCol "Flash"), flag2
false ( "Delphi" ).
IndexOf .
:
IndexOf(< >[, < >
[, < >]])

.
.
, .
, .
,
, ,
. , .
int indx;
indx = lstCol.IndexOf("Java");

indx 2.
LastIndexOf IndexOf ,
.
.
,
9 .
string output = "";
foreach (string str in lstCol)
{
output += str + "\r\n";
}

11.

205


Silverlight .
List
.
,
-. , , , .

Person. F (), N1 ()
N2 () Platforms List<string> ( ;
, List).
class Person
{
public string F { get; set; }
public string N1 { get; set; }
public string N2 { get; set; }
public List<string> Platforms { get; set; }
public Person()
{
Platforms = new List<string>();
}
}

List<string>
Platforms .
.
List<Person> lstPersons;
lstPersons = new List<Person>();

.
Person prs;
prs = new Person();
prs.F = "";
prs.N1 = "";
prs.N2 = "";
prs.Platforms.Add("Flash");
lstPersons.Add(prs);
prs = new Person();
prs.F = "";

206

III. C#

prs.N1 = "";
prs.N2 = "";
prs.Platforms.Add("HTML + CSS + JavaScript");
prs.Platforms.Add("Flash");
prs.Platforms.Add("Java");
lstPersons.Add(prs);
prs = new Person();
prs.F = "";
prs.N1 = "";
prs.N2 = "";
prs.Platforms.Add("Silverlight");
lstPersons.Add(prs);

: Person,
prs, lstPersons.
,
"" Platforms Person,
, , , , .
, Person
prs .
, .
prs = lstPersons[2];
bool flag = prs.Platforms.Contains("Java");

,
Java.
prs = lstPersons[0];
prs.F = "";

.
prs = lstPersons[1];
prs.Platforms.Add("Silverlight");

Silverlight.
, List . , . ,
, .
!

11.

207

Dictionary
Dictionary.
,
. , List, . ,
Dictionary (, ).
, ,
Silverlight .

Dictionary
Dictionary, , :
. :
Dictionary<< >, < >>
< >;

, .
new
:
new Dictionary<< >, < >>()
Dictionary<string, string> dicDict;
dicDict = new Dictionary<string, string>();

dicDict, .


Dictionary Count, .
.


Add :
Add(<>, <>)

208

III. C#

,
. .
dctDict.Add("hcjs", "HTML + CSS + JavaScript");
dctDict.Add("fl", "Flash");
dctDict.Add("j", "Java");
dctDict.Add("sl", "Silverlight");

Remove , . true,
, false (, ).
dctDict.Remove("fl");

Clear , . .


, Item.
.
string st;
st = dctDict.Item["sl"];

Item Dictionary . .
string st;
st = dctDict["sl"];

,
.
dctDict["sl"] = "Silverlight 3";

TryGetValue .
TryGetValue(< >, out <, >)

, , , , , . TryGetValue true,
, false .
string st;
if (dctDict.TryGetValue("fl", out st))
. . .

11.

209


ContainsKey ,
, . true, , false .
bool flag1, flag2;
flag1 = dctDict.ContainsKey("fl");
flag2 = dctDict.ContainsKey("d");

ContainsValue , , .
true, , false .
bool flag1, flag2;
flag1 = dctDict.ContainsValue("Flash");
flag2 = dctDict.ContainsValue("Delphi");


.
"-",
.
KeyValuePair,
.
foreach (KeyValuePair<string, string> kvp in dctDict)

, ,
.
KeyValuePair :
 Key ;
 Value .
string outputKeys, outputValues;
foreach (KeyValuePair<string, string> kvp in dctDict)
{
outputKeys += kvp.Keys + "\r\n";
outputValues += kvp.Values + "\r\n";
}


, .

210

III. C#

Queue
Queue , . " , ". ,
, ,
, .
, List.
Queue<string> queQ;
queQ = new Queue<string>();

Enqueue ,
. .
queQ.Enqueue("HTML + CSS + JavaScript");
queQ.Enqueue("Flash");
queQ.Enqueue("Java");
queQ.Enqueue("Silverlight");

Dequeue , (,
), ;
. .
string st1;
st = queQ.Dequeue();

st1 "HTML + CSS


+ JavaScript" queQ.
, "Flash".
Peek , .
.
string st2;
st = queQ.Peek();

st2 "Flash" queQ.


.
Queue Count Clear Contains.

Stack
Stack , -
. , " , ".

11.

211

.
Stack<string> stkStack;
stkStack = new Stack<string>();

Push ("") , . .
stkStack.Push("HTML + CSS + JavaScript");
stkStack.Push("Flash");
stkStack.Push("Java");
stkStack.Push("Silverlight");

Pop ("") ,
, ;
. .
string st1 = stkStack.Pop();
string st2 = stkStack.Pop();

st1 st2 "Silverlight" "Java" . stkStack .


Peek , .
.
string st;
st = stkStack.Peek();

st "Flash" stkStack
. .
Stack Count Clear Contains.

,

Silverlight,
.
, .
"" List.
, .
, , ListBox () Items.
6 , ItemCollection, FrameworkElement.
ListBoxItem, .

212

III. C#

lstList .
lstList.Item.Clear();
lstList.Item.Add(" ");
lstList.Item.Add(" ");

,
. , ,
.
! , ,
, Children.
UIElementCollection UIElement,
FrameworkElement
.
, , . .
Children
. , XAML- (,
, ).
,
, Silverlight.
.
, .
13,
.

?
C# . , Silverlight-.
.
, Silverlight
(,
). , ,
C#.

12

C#
Silverlight, . . "" , , , , ,
.
. ,
, . .


Silverlight-
.
, .
. -
, . , - "" ( ,
).
, .
?
, Silverlight ,
. , , . , - .

214

III. C#

, , , .
, Silverlight, , , , .
, . Silverlight- .


? , . . -
. ( " ",
.) ,
, , .

Silverlight. , , .
,
.
, ( ),
. .
, "" , , -
.
. , , . "" ,
, . , , .
, . : , ,
.
: ,
. , . , ,
.

12.

215

, ,
Silverlight, .
Silverlight "", .


Silverlight ,
. ( , ,
Silverlight.)
. 12.1.
12.1. Silverlight

Exception
SystemException

Exception

-
,

ArrayTypeMismatchException

SystemException

IndexOutOfRangeException

SystemException

InvalidCastException

SystemException

InvalidOperationException

SystemException

NullReferenceException

SystemException

OutOfMemoryException

SystemException

StackOverflowException

SystemException

ArgumentException

SystemException

-
,

216

III. C#
12.1 ()

ArgumentNullException

ArgumentException


null

ArgumentOutOfRangeException

ArgumentException

ArithmeticException

SystemException

-
,

DivideByZeroException

ArithmeticException

NotFiniteNumberException

ArithmeticException

,


(, + NaN)

OverflowException

ArithmeticException



,
(, int
short)

Message, . , .


Silverlight.


, . :
, .


,
.

12.

217

try
< , >
catch (< > < >)
< , >

, try catch. " try-catch".


, ( try), , , catch. , , ,
, . , ,
.
catch,
, , .
try
{
int
int
}
catch
{
. .
}

x = 1, y = 0;
z = x / y;
(DivideByZeroException e)
.

DivideByZeroException
.
catch .
try
{
. .
}
catch
{
. .
}
catch
{
. .
}

.
(DivideByZeroException e)
.
(ArithmeticException e)
.

218

III. C#

catch (SystemException e)
{
. . .
}

catch,
DivideByZeroException. , . , catch .
catch, ( ArithmeticException). , DivideByZeroException, catch .
catch, ,
(
SystemException). ,
DivideByZeroException, ArithmeticException,
catch .
, catch,
( DivideByZeroException),

(ArithmeticException SystemException).
"", "" "" .


,
, ,
try-catch .
< try-catch>
finally
< , >

- , finally, " finally".


, , , , try-catch .
try
{
btnDoCompute.IsEnabled = false;
. . .
}

12.

219

catch (ArithmeticException e)
{
. . .
}
finally
{
btnDoCompute.IsEnabled = true;
}

finally , , .


,
Silverlight ,
. ,
, .
, , .
ArgumentOutOfRangeException e = new ArgumentOutOfRangeException
(" .");

ArgumentOutOfRangeException. , ,
.
, . , , .

. throw,
.
throw e;

.
. ,
Silverlight.

220

III. C#

?
Silverlight,
, . C#.
Silverlight.
, .
, ...

IV


.
LINQ
13.

14.

LINQ

13



C# ,
. C#-. .

. ?
? .


, - ? , C#.
txtMillimetres.Text = cnvConvertor.Millimetres;

Text txtMillimetres
Millimetres cnvConvertor. (, .)
, C# .
, ? , ,
txtMillimetres ,
Millimetres cnvConvertor, C#-?
XAML-,
Text txtMillimetres
Millimetres cnvConvertor, Millimetres. Silverlight
.

224

IV. . LINQ

, Text
txtMillimetres Millimetres cnvConvertor.
, , .
, . ,
- HorizontalAlignment,
IsChecked, SelectedIndex . Silverlight .
, ,
.
, .


.
Convertor, ,
.
Silverlight-.
Visual Web Developer 2008
Convertor3.
, txtInches txtMillimetres btnConvert.
, Convertor.
Click btnConvert, . . .
XAML-
C#-. Convertor3 Convertor.
MainPage.
public class Convertor
{
private double fInches;
public string Inches
{
get
{
return fInches.ToString();
}
set
{
double dInches = 0;
double.TryParse(value, out dInches);

13.

225

if (dInches != fInches)
{
fInches = dInches;
}
}
}
public string Millimetres
{
get
{
double dMillimetres = fInches * 25.4;
return dMillimetres.ToString();
}
}
}

fInches
. .
Inches.
, , get- set. Get- ,
. Set-
fInches.
,
, ;
, .
Converter
Millimetres. , . .
get-. fInches,
, .
Converter ; ,
Object, (
-). Converter , .
, Converter . ,
.
C#-. XAML-.
.

226

IV. . LINQ

Silverlight-
.

,
Convertor. Load
, ,
InitializeComponent.
, . new.
. Silverlight, , , .
Convertor,
Convertor3. ( 4, Visual Web Developer 2008
,
.) Convertor3 XAML- , ,
<UserControl>, ,
xmlns.
. <UserControl> xmlns, , ,
. local (, Visual Basic, my). . Visual Web Developer 2008
, ;
Convertor3 in assembly Convertor3
Convertor3 , . . . :
xmlns:local="clr-namespace:Convertor3"

, Visual Web Developer 2008 xmlns , ,


. , , Build < > Build.

. .
Silverlight ,
-

13.

227

( , .), . , , .

,
, 8 . !

UserControl, , Resources, ResourceDictionary ( 11). ,


Object ,
. , . . .
, ,
.
<UserControl> , Resources. , , . , , , , .
x:Key, , .

, -, . Silverlight .

! XAML-
<UserControl>,
Convertor:
<UserControl.Resources>
<local:Convertor x:Key="cnvConvertor"></local:Convertor>
</UserControl.Resources>

, ,
Convertor local. cnvConvertor
x:Key .
. .
, Silverlight . , ,
App.xaml, ,
<Application>. ,

228

IV. . LINQ

, , , .


, .
 -, Text txtInches -

Inches Convertor,
. Text
Inches.
 -, Text txtMillimetres

Millimetres Convertor. Millimetres Text.


txtMillimetres, . . .
Text .
Binding. ( ),
XAML.
< >="{Binding < >}"

, (
Binding) , , .
, , Binding, ( ). <
>=< > .
, .
Binding, , .
 Path ,

. , .
 Source , .

Source . ,
, , . ?

13.

229

.
Source :
{StaticResource < Resources>}

, Text txtMillimetres
Millimetres - cnvConvertor, <TextBox> :
Text="{Binding Path=Millimetres, Source={StaticResource cnvConvertor}}"

txtMillimetres
Millimetres - cnvConvertor
Text.
txtInches. : , Text Inches - cnvConvertor.
, Mode Binding.
BindingMode :
 OneWay -

( ; );
 TwoWay -

,
( );
 OneTime

( ).
, <TextBox>,
txtInches:
Text="{Binding Path=Inches, Source={StaticResource cnvConvertor},
Mode=TwoWay}

, , , ... "" . ,
Inches Convertor ,
txtInches .
! .
Text TextBox,

230

IV. . LINQ

, . ,
, , .
. - . ... ... . ?


, ,
, , , . , .
.
Convertor INotifyPropertyChanged,
PropertyChanged.
Millimetres; , .
, , , , , INotifyPropertyChanged.
, , . PropertyChanged
, .
INotifyPropertyChanged PropertyChanged
System.ComponentModel. , , . ( . 4.)
Convertor INotifyPropertyChanged .
; .
public class Convertor : System.ComponentModel.INotifyPropertyChanged
{
private double fInches;
public event System.ComponentModel.PropertyChangedEventHandler
PropertyChanged;
public string Inches
{
get
{
return fInches.ToString();
}

13.

231

set
{
double dInches = 0;
double.TryParse(value, out dInches);
if (dInches != fInches)
{
fInches = dInches;
NotifyPropertyChanged("Millimetres");
}
}
}
. . .
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}

PropertyChanged

PropertyChangedEventHandler . ( ,
event.)
Silverlight,
INotifyPropertyChanged.
NotifyPropertyChanged, PropertyChanged.
, ,
.
,
PropertyChanged . (
, .) . PropertyChanged
null, , , .
, .
: ,
( this), , .
, ;
NotifyPropertyChanged .

232

IV. . LINQ

NotifyPropertyChanged get-
Inches.
Millimetres, . . txtMillimetres.
, fInches
PropertyChanged ,
, Inches, ? "" , .
,
.
, .


, ( Mode TwoWay), Silverlight .
,
, Silverlight
.
Binding ValidatesOnExceptions. true, Silverlight , . false.
,
. Text
txtInches ValidatesOnExceptions true.
Text="{Binding Path=Inches, Source={StaticResource cnvConvertor},
Mode=TwoWay, ValidatesOnExceptions=True}"

set- Inches Convertor ( ):


set
{
double dInches = 0;
double.TryParse(value, out dInches);
if (dInches < 0)
{
throw new Exception(" ");
}

13.

233

if (dInches != fInches)
{
fInches = dInches;
NotifyPropertyChanged("Millimetres");
}
}

, , .
, ,
.
,
; , " ".

Convertor
Silverlight . , ,
.
INotifyPropertyChanged...

Visual Web Developer 2008


Convertor4. , ,
txtInches txtMillimetres (
). , Convertor3, .
Text txtMillimetres txtInches.
, .
, ,
Path Binding.
ElementName.
, txtInches
<TextBox> :
Text="{Binding Path=Text, ElementName=txtInches}"

, -
.
. , , .

234

IV. . LINQ


. , -
.
Silverlight .
,
IValueConverter. :
 Convert , -

( );
 ConvertBack ,

( ).
IValueConvertr

System.Windows.Data. ,

, .
:
 Object;
 , .
Type

, ;

 Object;
 ,

. CultureInfo , . , CultureInfo
System.Globalization,
.

. .
Object.
,
IValueConverter. Convert;
ConvertBack .
Convertor.
Convertor4.
public class Convertor : System.Windows.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)

13.

235

{
string sInches;
double dInches, dMillimetres;
sInches = value as string;
if (double.TryParse(sInches, out dInches))
{
dMillimetres = dInches * 25.4;
}
else
{
dMillimetres = 0;
}
return dMillimetres.ToString();
}
public object ConvertBack(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}

.
ConvertBack NotEmplementedException, , ( ).
, . XAML-
Convertor4 ( , ),
Convertor,
cnvConvertor ( ). Converter Binding.
Text="{Binding Path=Text, ElementName=txtInches,
Converter={StaticResource cnvConvertor}}"

, , ,
,
, .
! , .

236

IV. . LINQ


,
, C#-. Silverlight .
, .


Visual Web Developer 2008 ListDemo.
lstDemo. - .
, . ,
. lstDemo.
? 11 .
, "" ,
- . ,
INotifyCollectionChanged.
, ,
Silverlight ObservableCollection.
, ,
, .
System.
,
, .
ObservableCollection
Collections.ObjectModel.

Load
, -, . : ObservableCollection ListDemoItemCollection,

. ListDemo .
public class ListDemoItemCollection :
System.Collections.ObjectModel.ObservableCollection<string>
{
public ListDemoItemCollection()

13.

237

{
Add(" ");
Add(" ");
Add(" ");
Add(" ");
}
}

ObservableCollection ,
.
ListDemoItemCollection, XAML-.
XAML- ListDemo ,
colItems.
ItemsSource, .
colItems, .
<ListBox . . . ItemsSource="{StaticResource colItems}" . . .>

. , , ...


... .
.
- , .
11 Person, -. .
public class Person
{
public string F { get; set; }
public string N1 { get; set; }
public string N2 { get; set; }
public int Age { get; set; }
public List<string> Platforms { get; set; }
public Person()
{
Platforms = new List<string>();
}
}

238

IV. . LINQ

, Age, . ListDemo.
ListDemoItemCollection ,
Person.
public class ListDemoItemCollection :
System.Collections.ObjectModel.ObservableCollection<Person>
{
public ListDemoItemCollection()
{
Person prs;
prs = new Person();
prs.F = "";
prs.N1 = "";
prs.N2 = "";
prs.Age = 30;
prs.Platforms.Add("Flash");
Add(prs);
prs = new Person();
prs.F = "";
prs.N1 = "";
prs.N2 = "";
prs.Age = 25;
prs.Platforms.Add("HTML + CSS + JavaScript");
prs.Platforms.Add("Flash");
prs.Platforms.Add("Java");
Add(prs);
prs = new Person();
prs.F = "";
prs.N1 = "";
prs.N2 = "";
prs.Age = 38;
prs.Platforms.Add("Silverlight");
Add(prs);
}
}

lstDemo, Person
. DisplayMemberPath,
. .
<ListBox . . . ItemsSource="{StaticResource colItems}"
DisplayMemberPath="F" . . .>

13.

239

lstDemo,
F Person.
.
.


Person? . , .
, ,
. , . , ,
, , , . ,
, .
ItemTemplate,
.
DataTemplate , .
XAML-,
. , , , ItemTemplate, ,
DataTemplate, ,
.
<ListBox x:Name="lstDemo" ItemsSource="{StaticResource colItems}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel>
<TextBlock Text="{Binding Path=F}"></TextBlock>
<TextBlock Text="{Binding Path=N1}"></TextBlock>
<TextBlock Text="{Binding Path=N2}"></TextBlock>
</StackPanel>
<TextBlock Text="{Binding Path=Age}" FontSize="26"></TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

240

IV. . LINQ

"" . , -,
"", ,
, F, N1 N2. -,
, Age .
. :
, (. .
). . :
, , DisplayMemberPath,
, .
, , .
! !
,
SelectedItem. ,
, Object.
.


- "" Platforms Person. ,
, ?

lstDetail. . "" ,
Platforms , lstDemo. , SelectedItem ( !) Person.
C#-? DataContext, .
Object , .
, .
SelectionChanged lstDemo; , 6,
, .
.
private void lstDemo_SelectionChanged(object sender,
SelectionChangedEventArgs e)

13.

241

{
lstDetail.DataContext = (lstDemo.SelectedItem as Person).Platforms;
}

,
Person "" Platforms
DataContext lstDetail. ,
.
XAML- lstDetail
<ListBox> :
ItemsSource="{Binding}"

, ,
. , DataContext.
! .

DataGrid

.

DataGrid ( ""!).
DataGrid ( ) , , .
System.Windows.Controls,
System.Windows.Controls.Data.dll.
<data:DataGrid></data:DataGrid>

Visual Web Developer 2008 data. .

, , .
DataGrid ,
. .

, DataGrid ActualHeight,
ActualWidth, DataContext, FontFamily, FontSize, FontStretch, FontStyle,
FontWeight, Height, HorizontalAlignment, IsEnabled, IsTabStop, ItemsSource,

242

IV. . LINQ

Margin, MaxHeight, MaxWidth, MinHeight, MinWidth, Name, Padding, SelectedIndex,


SelectedItem, TabIndex, VerticalAlignment, Visibility Width, Focus
SelectionChanged.

IsReadOnly , true. false, , , ( ).


HorizontalScrollBarVisibility VerticalScrollBarVisibility , , ,
.
ScrollBarVisibility :
 Auto ;
 Hidden , -

-;
 Visible ;
 Disabled , -

-.
Auto.
HeadersVisibility ,
"" . DataGridHeadersVisibility;
Columns ("" ; ) None ("" ).
GridLinesVisibility ,
, .
DataGridGridLinesVisibility :
 None ;
 Horizontal , ;
 Vertical , ;
 All ( ).

, .
 CanUserReorderColumns

.
 CanUserResizeColumns -

, .

13.

243

 CanUserSortColumns

- , .
true , false . true.
AutoGenerateColumns . true , , , . false
, ,
Columns.
Columns , .
ObservableCollection<DataGridColumn>, DataGridColumn ,
.
Silverlight .
 DataGridTextColumn . -

.
 DataGridCheckBoxColumn .

.
 DataGridTemplateColumn , -

( ).
, - .
, . (
.)
, ActualWidth,
IsReadOnly, MaxWidth, MinWidth, Visibility Width.
Header .
DisplayIndex
.
.
 CanUserReorder

.
 CanUserResize -

, .
 CanUserSort -

, .

244

IV. . LINQ

true , false .
.
DataGridTextColumn DataGridCheckBoxColumn
Binding, .
.
DataGridTextColumn
FontStyle FontWeight.

FontFamily,

FontSize,

DataGridCheckBoxColumn IsThreeState. true , , , , , , false (


).
DataGridTemplateColumn
CellEditingTemplate.

CellTemplate
DataTemplate.
, ,
( ; ).
. Visual
Web Developer 2008 GridDemo. C#- Person
ListDemoItemCollection, ListDemo. XAML-
GridDemo
ListDemoItemCollection,
colItems.
grdDemo. ItemsSource,
colItems. - , , . .
!
,
Person. Platforms,
ObservableCollection, . (
DataGrid ,
Platforms . .) .
, .
: , , , , . ,
DataGridTextColumn.

13.

245

, AutoGenerateColumns false, . <data:DataGrid>,


, , :
<data:DataGrid.Columns>
<data:DataGridTextColumn Binding="{Binding Path=F}"
Header=""></data:DataGridTextColumn>
<data:DataGridTextColumn Binding="{Binding Path=N1}"
Header=""></data:DataGridTextColumn>
<data:DataGridTextColumn Binding="{Binding Path=N2}"
Header=""></data:DataGridTextColumn>
<data:DataGridTextColumn Binding="{Binding Path=Age}"
Header=""></data:DataGridTextColumn>
<data:DataGridTextColumn Binding="{Binding Path=Platforms.Count}"
Header="- "></data:DataGridTextColumn>
</data:DataGrid.Columns>

.
, Count ""
Platforms Person. -, " "!
. !
. <data:DataGrid> , ,
. ,
DataGridTemplateColumn, ,
.
<data:DataGridTemplateColumn Header="">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=F}"></TextBlock>
<TextBlock Text="{Binding Path=N1}"></TextBlock>
<TextBlock Text="{Binding Path=N2}"></TextBlock>
</StackPanel>
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
</data:DataGridTemplateColumn>

"" , , , ,
F, N1 N2.

246

IV. . LINQ

, , . ,
" ".


DataGrid
,
, DataGrid? !
DataGrid
, :
 , ;
 DataGridTemplateColumn;
 -

IsReadOnly true.
, , ,
true. .

IsReadOnly

, , - C#-,
, ,
INotifyPropertyChanged. ,
. , .

! - , ,
<Enter> . ,
<Esc>. <Esc> , .
, . . ,

, .

, .
. .

13.

247


DataGrid
,
. , .
, , DataGridTemplateColumn,
. , .
: ,
. , ,
(. .
DataGridTemplateColumn). ,
.
CellEditingTemplate
DataGridTemplateColumn. CellTemplate
.
1. ,
( , , , .).
2. , ,
Mode TwoWay.
<data:DataGridTemplateColumn>,
, :
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<StackPanel>
<TextBox Text="{Binding Path=F, Mode=TwoWay}"></TextBox>
<TextBox Text="{Binding Path=N1, Mode=TwoWay}"></TextBox>
<TextBox Text="{Binding Path=N2, Mode=TwoWay}"></TextBox>
</StackPanel>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>

. .
. .
, .
Silverlight.

248

IV. . LINQ

?

Silverlight .
, ,
, ,
, .
, . , . ,
LINQ, .

14

LINQ
Silverlight .
.
. Silverlight . LINQ, . , , ...

LINQ
, , -. , , , Flash.
?
.
, , .
, "" Platforms
"Flash". , "" , . , , Flash.
, C#-,
, . , . - !
" "...

250

IV. . LINQ

Silverlight ! .
,
, ,
.
, LINQ (LanguageINtegrated Query , ), C#-
MSIL. C#
, .
LINQ, , . XAML, , , ,
. Silverlight:
" " , .

LINQ SQL
(Structured Query Language ). , SQL, LINQ.


, , ,
LINQ. .
Visual Web Developer 2008 LINQDemo.

lstDemo
LINQ-. ,
.
<ListBox x:Name="lstDemo" ItemsSource="{Binding}"></ListBox>

, , DataContext. ( . 13.)

C#- Person
ListDemoItemCollection, ListDemo.
ListDemoItemCollection LINQCollection, -

14. LINQ

251

, , .

, ,

LINQ-,

ObservableCollection -.
List.

, , , InitializeComponent. Load
.
, LINQ. ?
 , -

, . .

 .
 ,

.
 , ( ,
- ).
, LINQCollection colPersons:
LINQCollection colPersons = new LINQCollection();

, colPersons
:
IEnumerable<string> qryPersons = from person in colPersons
select person.F;

qryPersons.
, .
? , ,
,
.
, ,
.
IEnumerable, -

252

IV. . LINQ

. , .
.
IEnumerable ,
. (string),
colPersons ,
.
, , . (
) , .
 colPersons -

person (from person in colPersons).


.
 F ,
person (select person.F).
, . lstDemo .
lstDemo.DataContext = qryPersons;

.
. !
.
IEnumerable<string> qryPersons = from person in colPersons
select person.F + " " + person.N1 + " " + person.N2;

, , , .
.
IEnumerable<Person> qryPersons = from person in colPersons select person;

, ,
. , 13. ,
.
, , :
from < > in <>
select < ,
 >

14. LINQ

253

from, in select.
from select.

.

, colPersons? ?
. select
. .
var qryPersons = from person in colPersons
select new { F = person.F, N1 = person.N1, N2 = person.N2 };

colPersons select
, , , . ,
: new,
,
(F, N1 N2). ,
, .
, , ...
? !
Silverlight.
Visual Web Developer 2008 , . .
 .
 .
 , -

.
,
.
 ,

Object.
.
, ,

254

IV. . LINQ

var. ,
Visual Web Developer 2008 ( ).
,
, . ,
.
.
, lstDemo DisplayMemberPath
, , . ListBox
!
: , , ObservableCollection, - , , . .
System.Collections.ObjectModel.ObservableCollection<string> colTemp =
new System.Collections.ObjectModel.ObservableCollection<string>();
foreach (var prs in qryPersons)
{
colTemp.Add(prs.F + " " + prs.N1 + " " + prs.N2);
}
lstDemo.DataContext = colTemp;

, . , var, . . .

, , .
...


, . ,
, .
, , , .

14. LINQ

255

where, .
where < >

,
3. true, . ,
.

where from select.


IEnumerable<string> qryPersons = from person in colPersons
where person.Age > 30
select person.F + " " + person.N1 + " " + person.N2;

, ,
30 .
IEnumerable<string> qryPersons = from person in colPersons
where person.Age < 30 && person.Platforms.Contains("Flash")
select person.F + " " + person.N1 + " " + person.N2;

, ,
30 Flash. && Contains. (
. 11.)


.
orderby ,
.
orderby < ,
 ,
 >

, (). , . .

. ,

256

IV. . LINQ

() descending, .
orderby from select. where, orderby
select.
IEnumerable<string> qryPersons = from person in colPersons
where person.Age <= 30
orderby person.F
select person.F + " " + person.N1 + " " + person.N2;

, ,
30 , .
IEnumerable<string> qryPersons = from person in colPersons
orderby person.Platforms.Count() descending, person.F
select person.F + " " + person.N1 + " " + person.N2;

,
, ,
, . Count.


. - , , .
Dept.
: ID ( ) Name
( ).
public class Dept
{
public short ID { get; set; }
public string Name { get; set; }
}

DeptCollection, .
public class DeptCollection :
System.Collections.ObjectModel.ObservableCollection<Dept>
{
public DeptCollection()
{
Dept dpt;

14. LINQ

257

dpt = new Dept();


dpt.ID = 1;
dpt.Name = " ";
Add(dpt);
dpt = new Dept();
dpt.ID = 2;
dpt.Name = "--";
Add(dpt);
}
}

.
Person DeptID, .
public short DeptID { get; set; }

LINQCollection,
DeptID - .
prs.F = "";
prs.N1 = "";
prs.N2 = "";
prs.DeptID = 1;
. . .
prs.F = "";
prs.N1 = "";
prs.N2 = "";
prs.DeptID = 1;
. . .
prs.F = "";
prs.N1 = "";
prs.N2 = "";
prs.DeptID = 2;

.
DeptCollection colDepts = new DeptCollection();

, , . ?
-
LINQCollection DeptCollection,
DeptID ID. , , .

258

IV. . LINQ

LINQCollection , .
DeptCollection , .
.
join, join, in, on equals.
join < > in < >
on < >
equals < >

join , ,
in . on
,
equals
.
join from .
var qryPersons = from person in colPersons
join dept in colDepts on person.DeptID equals dept.ID
select new {Name = person.F + " " + person.N1 + " " + person.N2,
Dept = dept.Name};

LINQCollection DeptCollection
, , , ,
. .


,
.
() - (
). , .
group.
group by.
group <, > by < >

group from join.

14. LINQ

259


IEnumerable. IGrouping, .
 Key ,

.
 Value "" ,

,
.
IGrouping ,
, "" .
IEnumerable<IGrouping<string, string>> qryDepts = from dept in colDepts
join person in colPersons on dept.ID equals person.DeptID
group person.F + " " + person.N1 + " " + person.N2 by dept.Name;

, , , , . ,
, .
, .
IEnumerable. IGrouping,
.

, ,
var (.
).

,
. lstDemo , ,
lstDetail , .
, ,
, , .
,
ObservableCollection.
.
colKeys colValues
.

260

IV. . LINQ

private System.Collections.ObjectModel.ObservableCollection<string>
colKeys;
private System.Collections.ObjectModel.ObservableCollection
<System.Collections.ObjectModel.ObservableCollection<string>> colValues;

colKeys .
colValues . , .
:
colKeys = new
System.Collections.ObjectModel.ObservableCollection<string>();
colValues = new System.Collections.ObjectModel.ObservableCollection
<System.Collections.ObjectModel.ObservableCollection<string>>();
foreach (IGrouping<string, string> dpt in qryDepts)
{
colKeys.Add(dpt.Key);
System.Collections.ObjectModel.ObservableCollection<string>
lst = new
System.Collections.ObjectModel.ObservableCollection<string>();
foreach (string prs in dpt)
{
lst.Add(prs);
}
colValues.Add(lst);
}
lstDemo.DataContext = colKeys;


colKeys colValues. colKeys , colValues .
lstDemo colKeys.
lstDemo SelectionChanged.
:
lstDetail.DataContext = colValues[lstDemo.SelectedIndex];

lstDemo .
colKeys, colValues.
, colValues lstDetail.

, .

14. LINQ

261


IEnumerable ,
, , ,
. ,
, .
, ,
.
. 14.1. .
14.1. IEnumerable,

Average

.
,

Count

LongCount

Max

.
,

Min

. ,

Sum

. ,

IEnumerable<string> qryAggregate = from person in colPersons


where person.Platforms.Contains("Java")
select person.F;
lblAggregate.Text = qryAggregate.Count().ToString();

, , Java. Count
, . . Java, ToString lblAggregate.
:
lblAggregate.Text = (from person in colPersons
where person.Platforms.Contains("Java")
select person.F).Count().ToString();

262

IV. . LINQ

? Count ,
, ,
. , , .
lblAggregate.Text = (from person in colPersons
select person.Platforms.Count()).Max().ToString();

lblAggregate , .


.

LINQ . , ,
, ,
- .
, , , . from, select group.
, :
IEnumerable<string> qryPlatforms = from person in colPersons
from platform in person.Platforms
orderby platform
select platform;

colPersons, from
. "" Platforms colPersons, from platform in person.Platforms.
, ""
colPersons, .
,
,
. , .
person in colPersons,

IEnumerable<string> qryPlatforms = from person in colPersons


from platform in person.Platforms
orderby platform
group platform by platform into plGroup
select plGroup.Key;

14. LINQ

263

, , , "" , .
, .
.
-
, , .
into,
group select. into . :
 group IGrouping, ;
 select , ,

. ,
select, , .
group plGroup. . , select, ,
.
"" :
var qryPersons = from person in colPersons
select new { FNN = person.F + " " + person.N1 + " " + person.N2,
Age = person.Age } into pr
group pr by pr.Age;

colPersons ,
FNN (, ) Age () .
, .
var qryDepts = from dept in colDepts
select new { deptname = dept.Name,
cnt = (from person in colPersons
where person.DeptID == dept.ID &&
person.Platforms.Contains("Silverlight")
select person).Count() };

colDepts , deptname (-

264

IV. . LINQ

) cnt ( ,
Silverlight ).
deptname , cnt .
colPersons ,
DeptID ID colDepts, "" Platforms "Silverlight". Count.




, - . . , .
, ,
let .
let < > = <>

, let, ,
C#, .
; .
, , , , , .

,
.
IEnumerable<string> qryPersons = from person in colPersons
let FNN = person.F + " " + person.N1 + " " + person.N2
orderby FNN descending
select FNN;

FNN,
, ,

14. LINQ

265

colPersons
.
IEnumerable<string> qryDepts = from dept in colDepts
let persons = (from person in colPersons where person.DeptID == dept.ID
select person)
where persons.Count() > 1
select dept.Name;

colDepts
persons, , , . (, , .)
, .
, , persons.


, .
, .
, ... . - , .
,
, - . DeptCollection, , .
dpt = new Dept();
dpt.ID = 3;
dpt.Name = "--";
Add(dpt);

... .
!
, join
. ,
. , join .
- . !

266

IV. . LINQ

LINQ,
. , , - ...
, , ,
. , .
,
:
IEnumerable<IGrouping<string, string>> qryDepts = from dept in colDepts
join person in colPersons on dept.ID equals person.DeptID
group person.F + " " + person.N1 + " " + person.N2 by dept.Name;

:
IEnumerable<IGrouping<string, string>> qryDepts = from dept in colDepts
join person in colPersons on dept.ID equals person.DeptID into prGroup
from pr in prGroup.DefaultIfEmpty(new Person())
group pr.F + " " + pr.N1 + " " + pr.N2 by dept.Name;

, join into,
. , , , , group.
, ( ) prGroup,
. , , .

. ,
group, .
DefaultIfEmpty pr.
DefaultIfEmpty? ,
. , , .
, .
, prGroup, DefaultIfEmpty
.
"", prGroup , DefaultIfEmpty , ,
Person, "" . , , "" .

14. LINQ

267

,
, . ,
, pr, . . , .

, Silverlight
. , SQL, .

.
.
. , ...

?
LINQ
Silverlight.
Visual Web Developer 2008
LINQ-, .
, ,
Silverlight. , .

268

IV. . LINQ


Silverlight.

15.

16.

17.

18.

19.

15

Silverlight : LINQ
. C#-, , .
- . !
Silverlight. Silverlight-.
XAML. ...


, . Silverlight
( XAML-).
Line . :
 X1 ;
 Y1 ;
 X2 ;
 Y2 ;
 Stroke ;
 StrokeThickness .

272

V. Silverlight.

, (X)
, (Y) .
X1, Y1, X2, Y2 StrokeThickness double. Stroke, Brush, ; -, .
XAML- ,
Silverlight. , , Green (),
Red (), Blue (), Black (), White () Transparent
(, "" ). Silverlight .
<Line X1="100" Y1="100" X2="300" Y2="200" Stroke="Aqua"></Line>

- ( Aqua Stroke).
Line . "", "" ""
. ,
,
"".
Line , : ( ,
), ( ), . Silverlight.

Rectangle . ; .
 Width .
 Height .
 Stroke .
 StrokeThickness .
 Fill .
Transparent,

. . .
 Opacity 0
( ) 1 ( ). 1.
 RadiusX -

. 0.

15.

273

 RadiusY

. 0.
Width, Height, StrokeThickness, Opacity, RadiusX RadiusY
, Stroke
Fill Brush.
Rectangle "" (Canvas).
5 Canvas.Left Canvas.Top.
, ;
.
<Canvas>
<Rectangle Canvas.Left="10" Canvas.Top="10" Width="100" Height="200"
Stroke="Green" StrokeThickness="10" Fill="Transparent"></Rectangle>
</Canvas>

, , .
, Fill.
Rectangle .
,
.
<Grid>
<Rectangle Stroke="Blue" Fill="Blue"></Rectangle>
<TextBox Margin="5,5,5,5"></TextBox>
</Grid>

"" . (. .
XAML- , ),
.
.
Ellipse Rectangle,
. Width, Height, Stroke,
StrokeThickness, Fill Opacity.
<Ellipse Canvas.Left="200" Canvas.Top="150" Stroke="Yellow" Fill="Yellow"
Width="100" Height="75"></Ellipse>

(Yellow) "".
<Ellipse Canvas.Left="100" Canvas.Top="100" Stroke="Black"
Width="200" Height="200"></Ellipse>

274

V. Silverlight.

, . . . ,
, , .


, Silverlight , , .
.
Polygon , . ,
,
. , .
,
, Points.
PointCollection Point, , . XAML-
< >,
< >, ; .
Polygon Stroke,
StrokeThickness, Fill Opacity.
"" Line, Polygon . "", "", "" .
<Polygon Points="0,100 100,0 100,200" Stroke="Black"></Polygon>

. ,
.
, , Polygon,
, . , . .
<Polygon Points="10,10 10,60 30,60 10,10 10,100 100,100 10,10"
Stroke="Black" Fill="Blue"></Polygon>

, . 15.1. ,
.

15.

275

. 15.1. ,
( FillRule EvenOdd)

, Silverlight ,

(, , ).
FillRule, FillRule EvenOdd
NonZero.
FillRule EvenOdd (, , ), Silverlight ""
, .
, ,
.
NonZero FillRule Silverlight
. ,
, ,
. , , .
, , , .
FillRule , XAML-, NonZero , .
, . 15.2.

. 15.2. ,
( FillRule NonZero)

276

V. Silverlight.

Polyline , , .
, Polygon.
<Polyline Points="0,100 100,0 100,200" Stroke="Black"></Polyline>

, .

.
, , Silverlight- , .
(, ), , .
Path. -
.
Path Data Geometry. Geometry
, ;
.
Path Stroke, StrokeThickness, Fill
.

Opacity.



, .
LineGeometry. StartPoint
EndPoint, , ,
. Point; XAML-
< >,< >;

.
<Path Stroke="Black">
<Path.Data>
<LineGeometry StartPoint="0,150" EndPoint="400,150"></LineGeometry>
</Path.Data>
</Path>

. (
...)

15.

277

.
RectangleGeometry.
:
 Rect ;
 RadiusX -

;
 RadiusY

.
RadiusX RadiusY .
Rect Rect. XAML-
:
< >,
< >,<>,<>
<RectangleGeometry Rect="20,20,200,200"
RadiusX="5" RadiusY="5"></RectangleGeometry>

.
. EllipseGeometry, :
 Center ;
 RadiusX ;
 RadiusY .

RadiusX RadiusY .
Center Point.
<EllipseGeometry Center="200,150"
RadiusX="100" RadiusY="75"></EllipseGeometry>

.

,
, . ,
, Line, Rectangle
Ellipse. ,
, .
GeometryGroup.
Geometry,
Data Path.

278

V. Silverlight.

GeometryGroup Children. GeometryCollection, Geometry. , ,


Children, .
, , .
GeometryGroup FillRule.
, Silverlight ,
, , , ().
<Path Stroke="Black" Fill="Blue">
<Path.Data>
<GeometryGroup>
<GeometryGroup.Children>
<GeometryCollection>
<RectangleGeometry Rect="150,0,100,300"></RectangleGeometry>
<RectangleGeometry Rect="0,100,400,100"></RectangleGeometry>
</GeometryCollection>
</GeometryGroup.Children>
</GeometryGroup>
</Path.Data>
</Path>

. , ,
.
<Path Stroke="Black" Fill="Blue">
<Path.Data>
<GeometryGroup>
<GeometryGroup.Children>
<GeometryCollection>
<EllipseGeometry Center="200,150" RadiusX="100"
RadiusY="100"></EllipseGeometry>
<RectangleGeometry Rect="150,100,100,100"></RectangleGeometry>
</GeometryCollection>
</GeometryGroup.Children>
</GeometryGroup>
</Path.Data>
</Path>

"" .

15.

279


PathGeometry,
, ,
, ,
(). "" Silverlight.
, ,
Figures . PathFigureCollection,
PathFigure, .
PathGeometry FillRule.
PathFigure, , Segments,
PathSegmentCollection;
PathSegment, . -, .
, PathFigure , .
 StartPoint

Point.
 IsClosed , -

.
false ( ), ,
true .
 IsFilled , -

; Path.
true ( ),
, false .
, .
? "" , .
,
.
 StartPoint

PathFigure.
 .
 .

, . PathFigure IsClosed true, . -

280

V. Silverlight.

IsFilled false,
.
LineSegment.
Point
Point.
<Path Stroke="Black" Fill="Blue">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="0,150" IsClosed="True" IsFilled="False">
<PathFigure.Segments>
<LineSegment Point="150,0"></LineSegment>
<LineSegment Point="150,300"></LineSegment>
</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="200,150">
<PathFigure.Segments>
<LineSegment Point="350,0"></LineSegment>
<LineSegment Point="350,300"></LineSegment>
<LineSegment Point="200,150"></LineSegment>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>

, .
. , .
PolyLineSegment , . Points, , ; Polygon
Polyline.
<Path Stroke="Black" Fill="Blue">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<PathFigure StartPoint="0,150" IsClosed="True" IsFilled="False">
<PathFigure.Segments>

15.

281

<PolyLineSegment Points="150,0 150,300"></PolyLineSegment>


</PathFigure.Segments>
</PathFigure>
<PathFigure StartPoint="200,150">
<PathFigure.Segments>
<PolyLineSegment Points="350,0 350,300
200,150"></PolyLineSegment>
</PathFigure.Segments>
</PathFigure>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>

, .
ArcSegment . , .
Point
Point.
Size . Size, XAML-
< >,< >;
.
RotationAngle , ,
, .
0.
SweepDirection , , SweepDirection :
 Counterclockwise (

);
 Clockwise .

IsLargeArc , 180 (
true) ( false; ).
<PathFigure StartPoint="0,0">
<PathFigure.Segments>
<ArcSegment Point="100,100" Size="100,50"></ArcSegment>
<ArcSegment Point="0,0" Size="50,100"></ArcSegment>
</PathFigure.Segments>
</PathFigure>

282

V. Silverlight.

. ...
<PathFigure StartPoint="0,0">
<PathFigure.Segments>
<ArcSegment Point="100,100" Size="100,50"></ArcSegment>
<ArcSegment Point="0,0" Size="100,50"
RotationAngle="90"></ArcSegment>
</PathFigure.Segments>
</PathFigure>

, .
( , ), BezierSegment. ,
Point.
 Point1 . -

, , . , Silverlight, , "" .

 Point2 .
 Point3 .
<PathFigure StartPoint="0,0">
<PathFigure.Segments>
<BezierSegment Point1="50,100" Point2="200,0"
Point3="100,300"></BezierSegment>
</PathFigure.Segments>
</PathFigure>

.

, PolyBezierSegment. Points
PointCollection
Point, . XAML-
< >,<
>,< >, ;
.
<PathFigure StartPoint="0,0">
<PathFigure.Segments>

15.

283

<PolyBezierSegment
Points="50,100,200,0,100,150,50,100,0,200,0,0"></PolyBezierSegment>
</PathFigure.Segments>
</PathFigure>

, , .

, Point1. Point2
.
Point.

QuadraticBezierSegment.

<PathFigure StartPoint="0,0">
<PathFigure.Segments>
<QuadraticBezierSegment Point1="50,100"
Point2="200,0"></QuadraticBezierSegment>
</PathFigure.Segments>
</PathFigure>

, .
, PolyQuadraticBezierSegment.
Points PointCollection Point, . XAML-
< >,< >, ; .
<PathFigure StartPoint="0,0">
<PathFigure.Segments>
<PolyQuadraticBezierSegment
Points="50,100,50,50,0,200,0,0"></PolyQuadraticBezierSegment>
</PathFigure.Segments>
</PathFigure>

... , , .
<PathFigure StartPoint="100,100">
<PathFigure.Segments>
<LineSegment Point="50,100"></LineSegment>
<ArcSegment Point="50,0" Size="100,50"></ArcSegment>
<BezierSegment Point1="0,0" Point2="100,50"
Point3="200,300"></BezierSegment>

284

V. Silverlight.

<QuadraticBezierSegment Point1="400,0"
Point2="0,0"></QuadraticBezierSegment>
</PathFigure.Segments>
</PathFigure>


- .
(. ). ,
, PathGeometry .

Border
Silverlight . Border, - . .
Border Child. UIElement; , Silverlight.
Border .
 BorderBrush Brush.
 Background Brush.
 BorderThickness
Thickness. XAML- <
>,< >,< >,
< >,

,
.
.
 CornerRadius

CornerRadius. XAML-
< >,<
>,<
>,< >,

,

. .

15.

285

Border ActualHeight, ActualWidth, Height,


HorizontalAlignment, Margin, MaxHeight, MaxLength, MaxWidth, MinHeight,
MinWidth, Name, Padding, VerticalAlignment, Visibility Width.
<Border BorderBrush="Black" BorderThickness="3" CornerRadius="5"
Padding="10,10,10,10">
<data:DataGrid>
. . .
</data:DataGrid>
</Border>

DataGrid .


,
Silverlight . ,
, "" . ,
Foreground,
"" (, ), Background,
, BorderBrush, .
?
Silverlight . ,
,
. .
Silverlight ; "" .
Brush.


.
, . Silverlight !
<Line X1="100" Y1="100" X2="300" Y2="200" Stroke="Aqua"></Line>


Silverlight , .
.NET Framework Class
Library for Silverlight / System.Windows.Media Namespace / SolidColorBrush Class Silverlight.

286

V. Silverlight.

XAML- Silverlight,
,
SolidColorBrush, , .
, SolidColorBrush "", XAML-.
<Line X1="100" Y1="100" X2="300" Y2="200">
<Line.Stroke>
<SolidColorBrush Color="#984EA5"></SolidColorBrush>
</Line.Stroke>
</Line>

, Color
SolidColorBrush. Color XAML-
#[< >]< ><
>< >,
00 FF. , . , .
, SolidColorBrush Opacity, . 0 ( ) 1 ( ).
<SolidColorBrush Color="#984EA5" Opacity="0.5"></SolidColorBrush>


, , , . ,
.
Windows 2000
Windows XP Windows Vista.
. "" , , . . 15.3.

LinearGradientBrush. , .
,
, .

15.

287

StartPoint ( ) EndPoint ( ), Point. , XAML- < >,


< >,
.

. 15.3.

! ,
.
[0,0] , [1,1]
. , - , 0 1. , [0,5,0,5] .
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
</LinearGradientBrush>

[0,0]
[1,0]. , "" ( . 15.3) .
<LinearGradientBrush StartPoint="0,0" EndPoint="0,0.5">
</LinearGradientBrush>

288

V. Silverlight.

"" . ( , "" , .)
<LinearGradientBrush StartPoint="0,1" EndPoint="1,0">
</LinearGradientBrush>

, ""
, .
, . GradientStops,
GradientStopCollection, GradientStop.
GradientStop ,
, .
GradientStop ,
.
 Color Color.
 Offset -

, "" ,
0 ( ) 1 ( ).
<Rectangle Width="400" Height="300">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="Black" Offset="0"></GradientStop>
<GradientStop Color="White" Offset="0.5"></GradientStop>
<GradientStop Color="Blue" Offset="1"></GradientStop>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>

, . 15.3. "" .
( 0)
, ( 0,5)
, ( 1) .

15.

289

, ,
.
.
LinearGradientBrush Opacity, .
, ,
. ?
Silverlight SpreadMethod
LinearGradientBrush.
GradientSpreadMethod :
 Pad , -

( );
 Reflect , -

;
 Repeat

.
<LinearGradientBrush StartPoint="0,0" EndPoint="0,0.5"
SpreadMethod="Reflect">
. . .
</LinearGradientBrush>

, ""
(. 15.4). - , .

RadialGradientBrush.
, [0,0]
, [1,1] .
,
RadialGradientBrush, .
 GradientOrigin , -

, Point;
 Center , -

, Point;
 RadiusX ,

, ;
 RadiusY ,

, .

290

V. Silverlight.

. 15.4.

GradientStops.
RadialGradientBrush Opacity SpreadMethod.
<Rectangle Width="400" Height="300">
<Rectangle.Fill>
<RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5"
RadiusX="0.5" RadiusY="0.5">
<RadialGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="Black" Offset="0"></GradientStop>
<GradientStop Color="White" Offset="0.5"></GradientStop>
<GradientStop Color="Blue" Offset="1"></GradientStop>
</GradientStopCollection>
</RadialGradientBrush.GradientStops>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>

, . 15.4.

15.

291

<Rectangle Width="400" Height="300">


<Rectangle.Fill>
<RadialGradientBrush GradientOrigin="0.75,0.25" Center="0.5,0.5"
RadiusX="0.5" RadiusY="0.5">
<RadialGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="White" Offset="0"></GradientStop>
<GradientStop Color="Black" Offset="0.5"></GradientStop>
</GradientStopCollection>
</RadialGradientBrush.GradientStops>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>

, (. 15.5). ,
.

. 15.5.


, . ( 8.)

292

V. Silverlight.

ImageBrush.
ImageSource , ;
.
<Rectangle Width="400" Height="300">
<Rectangle.Fill>
<ImageBrush ImageSource="image.jpg"></ImageBrush>
</Rectangle.Fill>
</Rectangle>

AlignmentX , , , , .
AlignmentX :
 Left ;
 Right ;
 Center ( ).

AlignmentY .
AlignmentY :
 Top ;
 Bottom ;
 Center ( ).

Stretch , .
Stretch :
 None .

;
 Fill , -

. ( );
 Uniform , -

, . ;
 UniformToFill ,

, .
.

15.

293

ImageBrush Opacity.
<Rectangle Width="600" Height="800" Stroke="Black">
<Rectangle.Fill>
<ImageBrush ImageSource="image.jpg" AlignmentX="Right"
Stretch="None"></ImageBrush>
</Rectangle.Fill>
</Rectangle>

, , Silverlight ().
.

, , ,
Visual Web Developer 2008,
, . , 7 8.

,
MediaElement, .
( MediaElement 7.)
, 0, .
<MediaElement x:Name="melFill" Source="video.wmv"
Opacity="0"></MediaElement>

VideoBrush. SourceName, MediaElement, .


<Rectangle Width="400" Height="300" Stroke="Black">
<Rectangle.Fill>
<VideoBrush SourceName="melFill"></VideoBrush>
</Rectangle.Fill>
</Rectangle>

VideoBrush AlignmentX, AlignmentY,


Opacity Stretch.

294

V. Silverlight.


,
.
XAML-, , . ?
,
, . (
13.) .
<UserControl.Resources>
<LinearGradientBrush x:Key="lgbFill" StartPoint="0,0" EndPoint="1,0">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="Black" Offset="0"></GradientStop>
<GradientStop Color="White" Offset="0.5"></GradientStop>
<GradientStop Color="Blue" Offset="1"></GradientStop>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</UserControl.Resources>

, , . .
<Rectangle Width="400" Height="300" Stroke="{StaticResource lgbFill}"
Fill="{StaticResource lgbFill}"></Rectangle>

- ,
.
, , . .

?
Silverlight. , ,
. .
Silverlight .
, . -
.

16


Silverlight
. , .
Silverlight-. ,
.

Silverlight.

Silverlight ,
, .
, -.
Silverlight .
. - .


, .
Clip, .
Clip Geometry. ,
Geometry, . . ,
( LineGeometry), .
15.

296

V. Silverlight.

,
, . , , .
<Image Source="image.jpg">
<Image.Clip>
<EllipseGeometry Center="150,200" RadiusX="150"
RadiusY="200"></EllipseGeometry>
</Image.Clip>
</Image>

. ,
(. 16.1).

. 16.1.



. , , , . . .

16.

297

. ;
.
OpacityMask,
. Brush.
<Image Source="image.jpg">
<Image.OpacityMask>
<RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5"
RadiusX="0.5" RadiusY="0.5">
<RadialGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FF000000" Offset="0"></GradientStop>
<GradientStop Color="#99000000" Offset="0.75"></GradientStop>
<GradientStop Color="#00000000" Offset="1"></GradientStop>
</GradientStopCollection>
</RadialGradientBrush.GradientStops>
</RadialGradientBrush>
</Image.OpacityMask>
</Image>

(. 16.2).

. 16.2.

298

V. Silverlight.


. ,
: .
Effect,
. Effect; -, .
BlurEffect.
Radius,
; 5.
<TextBlock Text="!" FontSize="36">
<TextBlock.Effect>
<BlurEffect></BlurEffect>
</TextBlock.Effect>
</TextBlock>

(. 16.3).

. 16.3.

DropShadowEffect.
, .
 BlurRadius

. 5.

 Color Color.

#FF000000 ( ).

 Direction -

. 315.

 Opacity

0 ( ) 1 ( ; ).

 ShadowDepth

. 5.

16.

299

<TextBlock Text="!" FontSize="36">


<TextBlock.Effect>
<DropShadowEffect Color="#FFCCCCCC"
ShadowDepth="10"></DropShadowEffect>
</TextBlock.Effect>
</TextBlock>

(. 16.4).

. 16.4.

, , , , , . .
Silverlight , . : .


, , . .
, ( Geometry) ( Brush).

RenderTransform.

 Transform.
 Transform

RelativeTransform.
, , , , ( 15).

300

V. Silverlight.

Transform.
-, .
(, ) , . TranslateTransform. X Y, .

, .
<TextBlock Text="!" FontSize="36">
<TextBlock.RenderTransform>
<TranslateTransform X="2" Y="2"></TranslateTransform>
</TextBlock.RenderTransform>
</TextBlock>
<TextBlock Text="!" FontSize="36"
Foreground="Aqua"></TextBlock>

- .
, , 2 . -
; ,
.
<Rectangle Width="400" Height="300">
<Rectangle.Fill>
<RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5"
RadiusX="0.5" RadiusY="0.5">
<RadialGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="Black" Offset="0"></GradientStop>
<GradientStop Color="White" Offset="0.5"></GradientStop>
<GradientStop Color="Blue" Offset="1"></GradientStop>
</GradientStopCollection>
</RadialGradientBrush.GradientStops>
<RadialGradientBrush.RelativeTransform>
<TranslateTransform X="0.25" Y="-0.25"></TranslateTransform>
</RadialGradientBrush.RelativeTransform>
</RadialGradientBrush>
</Rectangle.Fill>
</Rectangle>

, ,
.

16.

301

, , . . RelativeTransform,
.
ScaleTransform . , .
 ScaleX ScaleY , ,

. 1 (. . ).

 CenterX CenterY

, "" "" .
. 0; , [0,0]
.

<TextBlock Text="!" FontSize="36">


<TextBlock.RenderTransform>
<ScaleTransform CenterX="200" ScaleX="0.5"
ScaleY="3"></ScaleTransform>
</TextBlock.RenderTransform>
</TextBlock>


. ,
[200,0]
; ""
"" .
, RotateTransform.
, .
 Angle -

. , . 0.

 CenterX CenterY

, .
. 0; , [0,0] .

302

V. Silverlight.

<TextBlock Text="!" FontSize="36">


<TextBlock.RenderTransform>
<RotateTransform Angle="45"></RotateTransform>
</TextBlock.RenderTransform>
</TextBlock>

- ...
SkewTransform , .
.
 AngleX AngleY

.
, . 0.

 CenterX CenterY

, .
. 0; , [0,0] .

<TextBlock Text="!" FontSize="36">


<TextBlock.RenderTransform>
<SkewTransform AngleX="-45"></SkewTransform>
</TextBlock.RenderTransform>
</TextBlock>

.
<Rectangle Width="400" Height="300">
<Rectangle.Fill>
<RadialGradientBrush GradientOrigin="0.5,0.5" Center="0.5,0.5"
RadiusX="0.5" RadiusY="0.5">
<RadialGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="Black" Offset="0"></GradientStop>
<GradientStop Color="White" Offset="0.5"></GradientStop>
<GradientStop Color="Blue" Offset="1"></GradientStop>
</GradientStopCollection>
</RadialGradientBrush.GradientStops>
<RadialGradientBrush.RelativeTransform>
<SkewTransform CenterX="0.5" CenterY="0.5"
AngleX="45"></SkewTransform>
</RadialGradientBrush.RelativeTransform>
</RadialGradientBrush>

16.

303

</Rectangle.Fill>
</Rectangle>

, ,
.
- ...

.

- , . .
TransformGroup.
Transform,
, ,
.
TransformGroup Children. TransformCollection, Transform.
, , Children, .
, , , .
, , , XAML-.
<TextBlock Text="!" FontSize="36">
<TextBlock.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<TransformCollection>
<RotateTransform Angle="-90"></RotateTransform>
<TranslateTransform Y="400"></TranslateTransform>
</TransformCollection>
</TransformGroup.Children>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>

90 , 400 ( ).
, .

304

V. Silverlight.


Silverlight . , , Silverlight 3;
.
.
Projection, Projection.
-, .

PlaneProjection.

PlaneProjection ,
.
 RotationX, RotationY RotationZ

X, Y Z
. , . 0.

 CenterOfRotationX, CenterOfRotationY CenterOfRotationZ -

, ,
X, Y Z. 0 ( )
1 ( ). 0,5, 0,5 0 ; ,
[0,5,0,5,0] .

 LocalOffsetX, LocalOffsetY LocalOffsetZ -

X, Y Z. , ,
. 0.

 GlobalOffsetX, GlobalOffsetY GlobalOffsetZ

X, Y Z. , , . 0.

<Image Source="image.jpg">
<Image.Projection>
<PlaneProjection RotationY="-30" RotationZ="20"
GlobalOffsetZ="-30"></PlaneProjection>

16.

305

</Image.Projection>
</Image>

30 Y,
20 Z Z
"" 30 .
. 16.5. , ...

. 16.5.

, , .
.

?
Silverlight.
, ,
, .
" " , .
.

17


Silverlight, .
,
, . ,
?
Silverlight-, . -, Silverlight ""
""! XAML-!

Silverlight-
. , ,
, .
, Silverlight - . - , ,
, , - .
,
. .
.
,
( ), Silverlight .
, ()
,

17.

307

. , ( ), , , , , . ,
.
: , . , .
,
. ,
. , ,
Silverlight: "
".
Silverlight ,
,
(. ).
, . . ,
.
,
. , ,
, (. . ).
.
Silverlight . ; , .
, , .
- ,
.
.
( ).
. ,
. , ,
Loaded .

308

V. Silverlight.

.
.

, .
.


, . Silverlight .
(
Image) , , "
". Opacity
1 0. ,
10 .
, .
C#-.
Storyboard.
Children TimelineCollection,
Timeline . Children ,
.
<Storyboard x:Name="sbdDemo">
</Storyboard>


, Silverlight.
. ( 13.)
<UserControl.Resources>
<Storyboard x:Name="sbdDemo">
</Storyboard>
</UserControl.Resources>

,
. ,
( x:Name). Silverlight, -,
, , , C#-. , ...

17.

309

. Silverlight, .
 ColorAnimation Color,

. . .
 DoubleAnimation .

 PointAnimation Point,

. . .

Opacity , DoubleAnimation.
: .
, ;
.
From .
, . , DoubleAnimation
, ColorAnimation Color, PointAnimation Point.
From , (, XAML-, ).
To .
. ,
.
By ,
. , ,
. ,
,
.
Duration .
Duration. XAML-
[<>:]<>:<>:<>[.< >].
<DoubleAnimation . . . Duration="0:0:10" . . .>

, 10 .
Duration
Automatic. .
<DoubleAnimation . . . Duration="Automatic" . . .>

310

V. Silverlight.

?
:
 Storyboard.TargetName ;
 Storyboard.TargetProperty .

, XAML- :
<UserControl.Resources>
<Storyboard x:Name="sbdDemo">
<DoubleAnimation From="1" To="0" Duration="0:0:10"
Storyboard.TargetName="imgDemo"
Storyboard.TargetProperty="Opacity"></DoubleAnimation>
</Storyboard>
</UserControl.Resources>

imgDemo .
Loaded
, :
sbdDemo.Begin();

Begin .
. , " " 10 .
.
<Storyboard x:Name="sbdDemo">
<PointAnimation To="150,0" Duration="0:0:10"
Storyboard.TargetName="lngDemo"
Storyboard.TargetProperty="StartPoint"></PointAnimation>
</Storyboard>
. . .
<Path Stroke="Black">
<Path.Data>
<LineGeometry x:Name="lngDemo" StartPoint="0,150"
EndPoint="400,150"></LineGeometry>
</Path.Data>
</Path>

. PointAnimation , StartPoint . , -

17.

311

(150,0);
, XAML- (0,150).
<Storyboard x:Name="sbdDemo">
<ColorAnimation To="Green" Duration="0:0:10"
Storyboard.TargetName="gdsDemo"
Storyboard.TargetProperty="Color"></ColorAnimation>
</Storyboard>
. . .
<Rectangle Stroke="Black">
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<LinearGradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop x:Name="gdsDemo" Color="Blue"
Offset="0"></GradientStop>
<GradientStop Color="Red" Offset="1"></GradientStop>
</GradientStopCollection>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>

,
ColorAnimation.
,
. .
FillBehavior , , .
FillBehavior :
 HoldEnd (-

);

 Stop .

AutoReverse . false (, ,
), . true, , ; . , ,
, .
: AutoReverse true,
FillBehavior .

312

V. Silverlight.

, FillBehavior
HoldEnd.
, . ,
,
, . RepeatBehavior.
RepeatBehavior XAML- :
 < >x -

 [<>:]<>:<>:<>[.< >]

 Forever .

BeginTime .
TimeSpan, 10. XAML- [<>:]<>:<>:<>[.< >]. 0,
.
BeginTime . , .
. ,
EasingFunction IEasingFunction. , , , .
Graphics, Animation, and Media / Animation / Animation Overview Silverlight.
<Storyboard x:Name="sbdDemo">
<PointAnimation To="150,0" Duration="0:0:10"
Storyboard.TargetName="lngDemo"
Storyboard.TargetProperty="StartPoint">
<PointAnimation.EasingFunction>
<BounceEase EasingMode="EaseInOut"></BounceEase>
</PointAnimation.EasingFunction>
</PointAnimation>
</Storyboard>
. . .

17.

313

<Path Stroke="Black">
<Path.Data>
<LineGeometry x:Name="lngDemo" StartPoint="0,150"
EndPoint="400,150"></LineGeometry>
</Path.Data>
</Path>

, BounceEase.
.


. , Silverlight,
.
, , .
.
 ColorAnimationUsingKeyFrames
Color.
 DoubleAnimationUsingKeyFrames
.
 PointAnimationUsingKeyFrames

Point.
.

AutoReverse, BeginTime, Duration,


FillBehavior RepeatBehavior. From, To By , , .
KeyFrames, . :
 ColorKeyFrameCollection, ColorKeyFrame,

ColorAnimationUsingKeyFrames;

 DoubleKeyFrameCollection, DoubleKeyFrame,

DoubleAnimationUsingKeyFrames;

 PointKeyFrameCollection, PointKeyFrame,

PointAnimationUsingKeyFrames.

ColorKeyFrame, DoubleKeyFrame PointKeyFrame


, .

314

V. Silverlight.

,
. .
 LinearColorKeyFrame, LinearDoubleKeyFrame LinearPointKeyFrame -

 DiscreteColorKeyFrame, DiscreteDoubleKeyFrame DiscretePointKeyFrame

 SplineColorKeyFrame, SplineDoubleKeyFrame SplinePointKeyFrame -

, .

, , , . .

KeyTime. KeyTime XAML-


[<>:]<>:<>:<>[.< >].

Value.
.
.
, .
, ,
, . ,
PointAnimationUsingKeyFrames,
LinearPointKeyFrame, DiscretePointKeyFrame SplinePointKeyFrame.

.
.
, , .
LinearPointKeyFrame.
<LinearPointKeyFrame KeyTime="0:0:4"
Value="10,10"></LinearPointKeyFrame>

. KeyTime , Value Point.

17.

315

"" DiscretePointKeyFrame.
<DiscretePointKeyFrame KeyTime="0:0:5"
Value="10,100"></DiscretePointKeyFrame>

, .

, .
SplinePointKeyFrame.

KeySpline KeySpline. XAML-
< >,

< > <


>,<
>.

0 1.

<SplinePointKeyFrame KeyTime="0:0:10" Value="150,0"


KeySpline="0,0.75 0.75,1"></SplinePointKeyFrame>

, , " ".
XAML- :
<Storyboard x:Name="sbdDemo">
<PointAnimationUsingKeyFrames Duration="0:0:10"
Storyboard.TargetName="lngDemo"
Storyboard.TargetProperty="StartPoint">
<PointAnimationUsingKeyFrames.KeyFrames>
<LinearPointKeyFrame KeyTime="0:0:4"
Value="10,10"></LinearPointKeyFrame>
<DiscretePointKeyFrame KeyTime="0:0:5"
Value="10,100"></DiscretePointKeyFrame>
<SplinePointKeyFrame KeyTime="0:0:10"
Value="150,0" KeySpline="0,0.75 0.75,1"></SplinePointKeyFrame>
</PointAnimationUsingKeyFrames.KeyFrames>
</PointAnimationUsingKeyFrames>
</Storyboard>
. . .
<Path Stroke="Black">
<Path.Data>
<LineGeometry x:Name="lngDemo" StartPoint="0,150"
EndPoint="400,150"></LineGeometry>
</Path.Data>
</Path>

316

V. Silverlight.

, , ObjectAnimationUsingKeyFrames. Object, . . .
KeyFrames ObjectAnimationUsingKeyFrames ObjectKeyFrameCollection, ObjectKeyFrame,
.
- DiscreteObjectKeyFrame. ,
ObjectAnimationUsingKeyFrames ""
.
. , XAML-:
<Storyboard x:Name="sbdDemo">
<ObjectAnimationUsingKeyFrames Duration="0:0:5"
Storyboard.TargetName="recDemo" Storyboard.TargetProperty="Fill">
<ObjectAnimationUsingKeyFrames.KeyFrames>
<DiscreteObjectKeyFrame KeyTime="0:0:1">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Yellow"></SolidColorBrush>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:2">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Red"></SolidColorBrush>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:3">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Green"></SolidColorBrush>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:4">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Blue"></SolidColorBrush>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
<DiscreteObjectKeyFrame KeyTime="0:0:5">
<DiscreteObjectKeyFrame.Value>
<SolidColorBrush Color="Black"></SolidColorBrush>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames.KeyFrames>

17.

317

</ObjectAnimationUsingKeyFrames>
</Storyboard>
. . .
<Rectangle x:Name="recDemo" Stroke="Black" Fill="White"></Rectangle>

, ObjectAnimationUsingKeyFrames, Fill, Brush. !



? ?
. ?
! ,
, . .
, .
.
<Storyboard x:Name="sbdDemo">
<PointAnimation To="150,0" Duration="0:0:10"
Storyboard.TargetName="lngDemo"
Storyboard.TargetProperty="StartPoint"></PointAnimation>
<PointAnimation To="150,400" Duration="0:0:10"
Storyboard.TargetName="lngDemo"
Storyboard.TargetProperty="EndPoint"></PointAnimation>
</Storyboard>
. . .
<Path Stroke="Black">
<Path.Data>
<LineGeometry x:Name="lngDemo" StartPoint="0,150"
EndPoint="400,150"></LineGeometry>
</Path.Data>
</Path>

.
.
<Storyboard x:Name="sbdDemo">
<Storyboard>
<PointAnimation To="150,0" Duration="0:0:10"
Storyboard.TargetName="lngDemo"
Storyboard.TargetProperty="StartPoint"></PointAnimation>

318

V. Silverlight.

<PointAnimation To="150,400" Duration="0:0:10"


Storyboard.TargetName="lngDemo"
Storyboard.TargetProperty="EndPoint"></PointAnimation>
</Storyboard>
<ColorAnimation To="White" Duration="0:0:10"
Storyboard.TargetName="scbDemo"
Storyboard.TargetProperty="Color"></ColorAnimation>
</Storyboard>
. . .
<Path>
<Path.Stroke>
<SolidColorBrush x:Name="scbDemo" Color="Black"></SolidColorBrush>
</Path.Stroke>
<Path.Data>
<LineGeometry x:Name="lngDemo" StartPoint="0,150"
EndPoint="400,150"></LineGeometry>
</Path.Data>
</Path>

,
. , ,
.
. "".
, , . .
BeginTime.
TimeSpan (. 10)
. , . , 5 ,
3 ,
8 (5+3) .
SpeedRatio. , , .
; 1 ,
1 . 1 ( ).
<Storyboard x:Name="sbdDemo">
<Storyboard BeginTime="0:0:2" SpeedRatio="0.5">

17.

319

<PointAnimation To="150,0" Duration="0:0:10"


Storyboard.TargetName="lngDemo"
. . .

, , 2 2 ( SpeedRatio
0.5).


, C#-.
, Storyboard.
 Begin . .
 Stop .
 Pause .
 Resume Pause

.
Seek SeekAlignedToLastTick "" .
TimeSpan, , "" ;
"" , .
.
Seek "", ,
. SeekAlignedToLastTick ,
, .
sbdDemo.Seek(new TimeSpan(0, 0, 1));

"" .
SkipToFill ""
. . AutoReverse true, . RepeatBehavior Forever, "" ,
InvalidOperation.

320

V. Silverlight.

Storyboard,
Completed. .
private void sbdFirst_Completed(object sender, EventArgs e)
{
sbdSecond.Begin();
}

Completed sbdFirst, sbdSecond.

?
, Silverlight .
Flash, , .
. Silverlight-, . 2, .

18


Silverlight:
, , .
!..
, .
Silverlight-. , .
, .



. .
, - Silverlight 3.
.
, , . C#-, , new , Web-, .
- Silverlight . , ,
.
Silverlight 3
. . ,
. .

322

V. Silverlight.

, Silverlight- .
, (
). , , .
, ,
. "" ,
. ,
, .
, , .
: , ,
, , .
,
UserControl, Page.
( ).
, .
,
() . ; Silverlight -, .
- . .


. , -
. .
Visual Web Developer 2008 MultiPage.
ListDemo Person
ListDemoItemCollection. Person Platforms, -

18.

323

.
, , MultiPage.
.


"" Frame.
System.Windows.Controls,
System.Windows.Controls.Navigation.dll.
. , Visual Web Developer 2008 XAML-:
<navigation:Frame></navigation:Frame>

Visual Web Developer 2008


System.Windows.Controls System.Windows.Controls.Navigation.dll navigation.
.

Source Frame ,
(. . ).
Uri - XAML- . ( Uri 7.) XAML .
<navigation:Frame Source="/ListPage.xaml"></navigation:Frame>

ListPage.xaml. . , -
, "" , , .
8 , . , .
. .
pages. ( ,
8.) .
Source .
<navigation:Frame Source="/pages/ListPage.xaml"></navigation:Frame>

ListPage.xaml, pages.

324

V. Silverlight.

, . .


.
"" Solution Explorer
New Item Add. Add
New Item (. 18.1).

. 18.1. Add New Item

"" Visual C# Categories


Silverlight ( Silverlight-).
Templates Silverlight Page.
Name . Add. (
Cancel .)
Visual Web Developer 2008 , . , XAML-
C#-. Solution Explorer.
pages.
, ListPage.xaml.
, Visual Web Developer 2008 XAML-
. .

18.

325

<navigation:Page x:Class="MultiPage.ListPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:navigation="clr-namespace:System.Windows.Controls;
assembly=System.Windows.Controls.Navigation"
Title=" ">
<Grid x:Name="LayoutRoot">
</Grid>
</navigation:Page>

, Page.
,
System.Windows.Controls,
System.Windows.Controls.Navigation.dll. ,
System.Windows.Controls
navigation.
, Page ( , )
Title. , Web- . ( Web- Web; Web-,
.)
.
, Silverlight-.
x:Class, . , XAML.
XAML-, ,
"".
, .

ListDemoItemCollection.
<navigation:Page.Resources>
<local:ListDemoItemCollection
x:Key="colItems"></local:ListDemoItemCollection>
</navigation:Page.Resources>

"" "" . lstSpecs, - F. 13,


.

326

V. Silverlight.

btnToDetail.
,
lstSpecs .
. , , ,
.
,
DetailPage.xaml. .
, ;
, , .
, , Person. , , XAML-
C#- DataContext. , ,
, :
<TextBox Text="{Binding Path=F}" . . .>

XAML- .
btnToMain,
.

. , C#-.
Click (btnToDetail), . , -,
, -, , . .

18.

327

NavigationService Page.
NavigationService,
.
Navigate.
Uri, ,
. ,
true, false.
Click btnToDetail :
if (lstSpecs.SelectedIndex > -1)
{
NavigationService.Navigate(new Uri("/pages/DetailPage.xaml",
UriKind.Relative));
}

, lstSpecs - ,
, . Navigate Uri,
DetailPage.xaml. "" ,
Uri Relative UriKind.
(btnToMain) . Click :
NavigationService.Navigate(new Uri("/pages/ListPage.xaml",
UriKind.Relative));

Silverlight,
. Web-, Web-. Web Silverlight- !
, ,
(Forward) (Back) Web-.
NavigationService ,
. .
GoForward GoBack , ,
, .
.
CanGoForward CanGoBack true,
, false . .

328

V. Silverlight.

, Click
btnToMain :
if (NavigationService.CanGoBack)
{
NavigationService.GoBack();
}

NavigationService StopLoading.
. .
Page Loading. .
Frame CanGoForward CanGoBack
GoForward, GoBack, Navigate StopLoading. , ; .
 Navigating .
 Navigated .
 NavigationStopped -

StopLoading.
 NavigationFailed ,

(, ).

Page, .



, ,
.
, !
, , !
! . Silverlight
. , . , ,
, .

18.

329

(?).
< >=< >,
&.
, 1
num, :
/pages/DetailPage.xaml?num=1

, . , , , , , Unicode. ,
.

Click
btnToDetail :
if (lstSpecs.SelectedIndex > -1)
{
NavigationService.Navigate(new Uri("/pages/DetailPage.xaml?num=" +
lstSpecs.SelectedIndex, UriKind.Relative));
}

(num)
.
; Silverlight .
.
NavigationContext Page. NavigationContext, . QueryString,
(. 11); ,
.
Loaded . :
ListDemoItemCollection colSpecs;
int specNum = 0;

330

V. Silverlight.

if (NavigationContext.QueryString.ContainsKey("num"))
{
if (int.TryParse(NavigationContext.QueryString["num"], out specNum))
{
colSpecs = new ListDemoItemCollection();
LayoutRoot.DataContext = colSpecs[specNum];
}
}

, ,
, num.
ContainsKey, , . ,
TryParse.
, ,
.
ListDemoItemCollection, , .
, , ,
,
(LayoutRoot). . ,
,
.
, ... .

- (HyperlinkButton)
Silverlight- Web-,
HyperlinkButton. , , Web HTML.
<HyperlinkButton Content=""
NavigateUri="/pages/ListPage.xaml"></HyperlinkButton>

Content
HyperlinkButton. ContentControl; ,
.
, ,
NavigateUri Uri. XAML-
.
HyperlinkButton Click, .

18.

331

<HyperlinkButton x:Name="hlbToDetail" Content=""


Click="btnToDetail_Click"></HyperlinkButton>

Click
, .

HyperlinkButton
ActualHeight,
ActualWidth, FontFamily, FontSize, FontStretch, FontStyle, FontWeight, Height,
HorizontalAlignment, IsEnabled, IsTabStop, Margin, MaxHeight, MaxWidth,
MinHeight, MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility
Width Focus.

Web-
Silverlight Web-.
HyperlinkButton. NavigateUri
-. TargetName
_new Web- Web-
. !
<HyperlinkButton Content=" Silverlight"
NavigateUri="http://www.microsoft.com/rus/Silverlight/"
TargetName="_new"></HyperlinkButton>

,
Silverlight.

, Web-, TargetName _new, .

?
.
Web-.
, Silverlight-
. , .

19


,
. , () .
, .
. ,
, . Windows-
. -
Silverlight? , .
- , , - . Windows -, . - Silverlight?
.
Silverlight , - .


Silverlight .
GridDemo .


Silverlight ,
.
.

19.

333

 Web-, -

Silverlight-,
.
 . -

,
.
 -

.
 ( ) -

. Windows-.
 -

, .
 , -

.
, . : ...
Silverlight ,
MSIL , ,
, .
, ,
, ... ... ... . .
"--" .
, , , .
Silverlight . , , ,
: ,
. (, ,
Silverlight, . .)
, , , , , .
, "" , .
,
.
, ,
.
.

334

V. Silverlight.

,
. ChildWindow.
. Visual Web Developer 2008
GridDemo. XAML- , , grdDemo
"" :
<data:DataGrid . . . ItemsSource="{Binding}" . . .>

colItems, :
private ListDemoItemCollection colItems;


InitializeComponent :
colItems = new ListDemoItemCollection();
grdDemo.DataContext = colItems;

,
grdDemo.
,
C#- colItems.
,
C#-.

btnAdd. .


,
"" Solution Explorer
New Item Add.
Add New Item (. . 18.1).
Categories "" Visual C#,
, Silverlight. Templates
Silverlight Child Window. Name ,
; AddWindow.xaml.
Add. ( Cancel
.)
Visual Web Developer 2008 , , -

19.

335

Solution Explorer.
AddWindow.xaml,
.
. XAML-, .
<controls:ChildWindow x:Class="GridDemo.AddWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clrnamespace:System.Windows.Controls;assembly=System.Windows.Controls"
Width="400" Height="300"
Title=" ">
<Grid x:Name="LayoutRoot" Margin="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button x:Name="btnCancel" Content=""
Click="CancelButton_Click" Width="75" Height="23"
HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
<Button x:Name="btnOK" Content="" Click="OKButton_Click"
Width="75" Height="23" HorizontalAlignment="Right"
Margin="0,12,79,0" Grid.Row="1" />
</Grid>
</controls:ChildWindow>

, .
,
ChildWindow.
,
System.Windows.Controls, System.Windows.Controls.dll. ,
System.Windows.Controls controls.
, ChildWindow ( , ) Title.
Object , . ; .
ChildWindow Width Height,
. , , ,
, .

336

V. Silverlight.

ChildWindow HasCloseButton. true


, . false
. HasCloseButton true.
. x:Class .
XAML.
, "", ...
Visual Web Developer 2008 K
, . (
; .) :
,
.
Visual Web Developer 2008 Click. .
,
, . txtF, txtN1, txtN2 txtAge .
,
, .
K .


.
Click btnAdd. .
,
new. Silverlight .
Show
ChildWindow. .
, , no
comments:
AddWindow wndAdd = new AddWindow();
wndAdd.Show();

. .
"" . , K .

19.

337

, . , ,
, , , ... K "". , Visual Web Developer 2008 Click - , . ?
,
Close ChildWindow. .
Close , , ;
Click .
- ,
, K . ( .)
, - ,
.
DialogResult ChildWindow. null.
 , null.
 , -

,
<Ctrl>+<Shift>+<F4> Close,
false.
 , K, -

true.
 , ,

false.
 DialogResult -

.
AddWindow.xaml.cs
Click K , , .
, Click K :
this.DialogResult = true;

DialogResult
true. , -, , -, ,
, K.
Click :
this.DialogResult = false;

338

V. Silverlight.

, , .
DialogResult!


, K
,
. ?
, , , , Show
Click :
AddWindow wndAdd = new AddWindow();
wndAdd.Show();
if (wndAdd.DialogResult == true)
{
Person prs = new Person();
int iAge;
prs.F = wndAdd.txtF.Text;
prs.N1 = wndAdd.txtN1.Text;
prs.N2 = wndAdd.txtN2.Text;
if (int.TryParse(wndAdd.txtAge.Text, out iAge))
{
prs.Age = iAge;
}
colItems.Add(prs);
}

. ...
, , , , . , , ,
, , .
Show,
, , . ""
, , . .
:
Closed .
ChildWindow.

19.

339

Closed . .
.
Closed
.
private void wndAdd_Closed(object sender, EventArgs e)
{
AddWindow wndAdd = sender as AddWindow;
if (wndAdd.DialogResult == true)
{
Person prs = new Person();
int iAge;
prs.F = wndAdd.txtF.Text;
prs.N1 = wndAdd.txtN1.Text;
prs.N2 = wndAdd.txtN2.Text;
if (int.TryParse(wndAdd.txtAge.Text, out iAge))
{
prs.Age = iAge;
}
colItems.Add(prs);
}
}

, ;
Object. , AddWindow , .
, DialogResult
true. , ,
true, false null, true.
, , txtF, txtN1, txtN2 txtAge ,
.
Click , ,
Closed :
AddWindow wndAdd = new AddWindow();
wndAdd.Closed += wndAdd_Closed;
wndAdd.Show();

340

V. Silverlight.

.
,

K. , -
.
-
? ,
Loaded .
, , txtAge
20.
Loaded:
private void wndAdd_Loaded(object sender, EventArgs e)
{
(sender as AddWindow).txtAge.Text = "20";
}

Click ,
Closed :
AddWindow wndAdd = new AddWindow();
wndAdd.Loaded += wndAdd_Loaded;
wndAdd.Closed += wndAdd_Closed;
wndAdd.Show();

.
20. , !

-
-
. - , , ,
. -
.
 - Web- .

( Silverlight -
Windows.)
 - Web-. -

Web-, .

19.

341

 - , (K)

(K ).
 - , -

.
 - -

, .
-. ,
, , , -, , . ,
-, , K .
- MessageBox. Show. :
Show(< >[, < >, < >])

, ,
.
, -. , .
MessageBoxButton.
: OK ( -
K) OKCancel ( K ).
, - K.
Show MessageBoxResult.
: OK ( K) Cancel (
).
Click K
, , - , , , .
:
if (txtF.Text == String.Empty)
{
MessageBox.Show(" ");
txtF.Focus();
}

342

V. Silverlight.

else
{
if (txtN1.Text == String.Empty)
{
MessageBox.Show(" ");
txtN1.Focus();
}
else
{
this.DialogResult = true;
}
}

,
,
.
Silverlight .

?
Silverlight, . ,
,
.

. , Web-.
.

VI


Web-
20.

21.

22.

Web-

20


Silverlight
.
GridDemo , .
, ...
, , (, , ). , , -
(, Web-). !
.
, Silverlight 3 .


, Silverlight .
 ,

.
 , -

.
. , ,
.

346

VI. Web-


, , Silverlight
.
, .

. , .
, , , , . .
,
, , , . , , (
Web-).

GridDemo .
specs.dat, data.
, , . ,
, Person . "" Platforms "" ; .
, ,
.
.
btnSave btnLoad.
ListDemoItemCollection ; ,
. , .


, , , , ,
, .
GetUserStoreForApplication IsolatedStorageFile. .

20.

347

, GetUserStoreForApplication,
IsolatedStorageFile.
, .

- file. , ...

IsolatedStorageFile System.IO.
IsolatedStorage. ,
, .
System.IO.IsolatedStorage.IsolatedStorageFile isfData =
System.IO.IsolatedStorage.IsolatedStorageFile.
GetUserStoreForApplication();


, . , .

CreateDirectory
IsolatedStorageFile.
.
isfData.CreateDirectory("\\data\\temp");

data\temp. data,
temp. .
,
, . , Silverlight
( . 9);
, \\. .


,
OpenFile IsolatedStorageFile. , .
:
OpenFile(< >, <>[, < >])

348

VI. Web-


.
FileMode, Silverlight,
. :
 CreateNew ;
 Open ;
 OpenOrCreate , ,

, ;
 Append ,

;
 Truncate -

;
 Create ,

, , .
FileAccess, , . :
 Read ;
 Write ;
 ReadWrite , .

,
, .
FileMode FileAccess
System.IO. , , .
Silverlight-
. ,

. - ,
; .
,
. 21, ,
.
Silverlight . Stream; ,

20.

349

: , . , , , IsolatedStorageFileStream.

OpenFile
IsolatedStorageFileStream.

IsolatedStorageFileStream

System.IO.IsolatedStorage. ,

, .
System.IO.IsolatedStorage.IsolatedStorageFileStream issData =
isfData.OpenFile("\\data\\specs.dat", System.IO.FileMode.Create,
System.IO.FileAccess.Write);

Silverlight /data/specs.dat
, ,
. .
System.IO.IsolatedStorage.IsolatedStorageFileStream issData =
isfData.OpenFile("\\data\\specs.dat", System.IO.FileMode.Open,
System.IO.FileAccess.Read);


, . -"" StreamReader
StreamWriter. ,
.
, - . , StreamWriter. ,
.
StreamWriter System.IO.
, ,
.
, StreamWriter,
.
new
, .
System.IO.StreamWriter stwData = new System.IO.StreamWriter(issData);

350

VI. Web-

StreamWriter WriteLine. , , .
Silverlight. .
WriteLine ,
. .

StreamWriter
Unicode.
Person prs = colItems[0];
stwData.WriteLine(prs.F);
stwData.WriteLine(prs.N1);
stwData.WriteLine(prs.N2);
stwData.WriteLine(prs.Age);
foreach (string platform in prs.Platforms)
{
stwData.WriteLine(platform);
}
stwData.WriteLine();


: , , , . ,
.
:

30
Flash
<--

, WriteLine ,
, , .


.
StreamReader,
.

20.

351

StreamReader System.IO.
, ,
.
StreamReader, ,
new , .
System.IO.StreamReader strData = new System.IO.StreamReader(issData);

StreamReader ReadLine. .
(. . ), null.
.
ReadLine, . , null, , , , .
StreamReader ReadToEnd. ,
, . , . .
EndOfStream. true, , false, .
Person prs = new Person();
prs.F = strData.ReadLine();
prs.N1 = strData.ReadLine();
prs.N2 = strData.ReadLine();
if (int.TryParse(strData.ReadLine(), out iAge))
{
prs.Age = iAge;
}
while (!(strData.EndOfStream))
{
s = strData.ReadLine();
if (s == String.Empty)
{
break;
}
else
{
prs.Platforms.Add(s);
}
}
colItems.Add(prs);

352

VI. Web-

.
, , . , ,
.
, , . . , . , "" Platforms. ,
.



. -, -""
StreamWriter StreamReader,
. -, .
,
, . , .
try-finally,
finally -"" . ,
. ( try-finally 12.)
StreamWriter StreamReader Close. , "". , ,
.
strData.Close();

Close. .

.
.

20.

353


Silverlight
IsolatedStorageFile . .
FileExists true,
, false .
if (isfData.FileExists("\\data\\specs.dat"))
{
. . .

DirectoryExists true, , false .


if (!(isfData.DirectoryExists("\\data")))
{
isfData.CreateDirectory("\\data");
}

, \data, , , .
GetFileNames , .
, ,
, . , .
* ?. , . ,
*.* , *.dat
dat, ?.txt txt, .
GetFileNames ,
. : , ! , .
( 9.)
string[] files = isfData.GetFileNames("\\data\\*.txt");
if (files.Length > 0)
{
. . .

txt,
\data.

354

VI. Web-

GetDirectoryNames
, .
, ,
, .
, . .
string[] folders = isfData.GetDirectoryNames("\\?ata");
if (folders.Length > 0)
{
. . .

, , , "ata".


. IsolatedStorageFile, .
DeleteFile , . .

DeleteFile .
isfData.DeleteFile("\\data\\specs.dat");

DeleteDirectory ,
. .

DeleteDirectory , . .
isfData.DeleteDirectory("\\data");


,
. 1 048 576 , 1 .
Silverlight-, Web-,
. , ,

20.

355

, .
Silverlight-, ,
Web- .
-
,
. , , .
IsolatedStorageFile
. .
Quota, ,
(long).
.
AvailableFreeSpace
.
.
IncreaseQuotaTo ,
. , ,
, Yes No.
Yes, , IncreaseQuotaTo
true;
No, false.
long availSpace = 524288;
if (isfData.AvailableFreeSpace < availSpace)
{
if (isfData.IncreaseQuotaTo(isfData.Quota + availSpace))
{
. . .
}
else
{
. . .
}
}

,
512 (524 288 ) , , , . ,
IncreaseQuotaTo , ,

356

VI. Web-

. ,
1,5 .


, Silverlight
.
Remove IsolatedStorageFile.
.
isfData.Remove();

, .
- , ,
Silverlight,
.

Remove
.



. Dispose
IsolatedStorageFile. .
isfData.Dispose();

, .
GetUserStoreForApplication
IsolatedStorageFile.



, GridDemo

... ! !..

20.

357

Click (btnSave).
System.IO.IsolatedStorage.IsolatedStorageFile isfData =
System.IO.IsolatedStorage.IsolatedStorageFile.
GetUserStoreForApplication();
if (!(isfData.DirectoryExists("\\data")))
{
isfData.CreateDirectory("\\data");
}
System.IO.IsolatedStorage.IsolatedStorageFileStream issData =
isfData.OpenFile("\\data\\specs.dat", System.IO.FileMode.Create,
System.IO.FileAccess.Write);
System.IO.StreamWriter stwData = new System.IO.StreamWriter(issData);
foreach (Person prs in colItems)
{
stwData.WriteLine(prs.F);
stwData.WriteLine(prs.N1);
stwData.WriteLine(prs.N2);
stwData.WriteLine(prs.Age);
foreach (string platform in prs.Platforms)
{
stwData.WriteLine(platform);
}
stwData.WriteLine();
}
stwData.Close();
isfData.Dispose();

Click (btnLoad).
int iAge;
string s;
System.IO.IsolatedStorage.IsolatedStorageFile isfData =
System.IO.IsolatedStorage.IsolatedStorageFile.
GetUserStoreForApplication();
if (isfData.FileExists("\\data\\specs.dat"))
{
System.IO.IsolatedStorage.IsolatedStorageFileStream issData =
isfData.OpenFile("\\data\\specs.dat", System.IO.FileMode.Open,
System.IO.FileAccess.Read);
System.IO.StreamReader strData = new System.IO.StreamReader(issData);
colItems.Clear();
while (!(strData.EndOfStream))

358

VI. Web-

{
Person prs = new Person();
prs.F = strData.ReadLine();
prs.N1 = strData.ReadLine();
prs.N2 = strData.ReadLine();
if (int.TryParse(strData.ReadLine(), out iAge))
{
prs.Age = iAge;
}
while (!(strData.EndOfStream))
{
s = strData.ReadLine();
if (s == String.Empty)
{
break;
}
else
{
prs.Platforms.Add(s);
}
}
colItems.Add(prs);
}
strData.Close();
}
isfData.Dispose();

, , .


, . , ,
.
.
,
, .
, Silverlight.
.
GridDemo
. ,

20.

359

btnSaveToFile btnLoadFromFile.
, .


, , ,
.
SaveFileDialog.
Windows,
.
SaveFileDialog Filter,
, . ; - , .
Filter , :
< >|< ,
 >

(|).
*.< >.
, .
(*.dat)|*.dat

, dat.
(*.dat, *.txt)|*.dat;*.txt

, dat txt.
(*.dat)|*.dat| (*.txt)|*.txt|
 (*.*)|*.*

: dat,
txt .
,
, . , . *.* ( ),
.
FilterIndex . , FilterIndex

360

VI. Web-

, . , , .
; .
, ,
,
.
Filter ( ), ,
.
, DefaultExt
, , .
,
. ShowDialog.
, .
, true; , false. ShowDialog null;
, .
.

ShowDialog true, , . SafeFileName,
, . , .
OpenFile. Stream , . ,
. OpenFile .
, .

Click:
SaveFileDialog sfdData = new SaveFileDialog();
sfdData.Filter = " (*.dat)|*.dat|
 (*.txt)|*.txt| (*.*)|*.*";

20.

361

if (sfdData.ShowDialog() == true)
{
System.IO.Stream strData = sfdData.OpenFile();
System.IO.StreamWriter stwData = new System.IO.StreamWriter(strData);
foreach (Person prs in colItems)
{
stwData.WriteLine(prs.F);
stwData.WriteLine(prs.N1);
stwData.WriteLine(prs.N2);
stwData.WriteLine(prs.Age);
foreach (string platform in prs.Platforms)
{
stwData.WriteLine(platform);
}
stwData.WriteLine();
}
stwData.Close();
}

SaveFileDialog, ,
. , ,
, ShowDialog true. , ,
- null, true.
OpenFile,
StreamWriter, ,
. .
, .
. ,
( ,
Unicode) , .


,
.
, . OpenFileDialog, -

362

VI. Web-

Windows, .
OpenFileDialog Filter
FilterIndex ShowDialog. , SaveFileDialog.
,
File. FileInfo. FileInfo
.
, OpenText FileInfo.
, StreamReader, . .
OpenRead.
,
. FileStream, Stream.
OpenRead .
, FileInfo , .
 Name .
 Length

.
 Exists true, , false

.
. Click:
int iAge;
string s;
OpenFileDialog ofdData = new OpenFileDialog();
ofdData.Filter = " (*.dat)|*.dat|
 (*.txt)|*.txt| (*.*)|*.*";
if (ofdData.ShowDialog() == true)
{
System.IO.StreamReader strData = ofdData.File.OpenText();
colItems.Clear();
while (!(strData.EndOfStream))
{
Person prs = new Person();

20.

363

prs.F = strData.ReadLine();
prs.N1 = strData.ReadLine();
prs.N2 = strData.ReadLine();
if (int.TryParse(strData.ReadLine(), out iAge))
{
prs.Age = iAge;
}
while (!(strData.EndOfStream))
{
s = strData.ReadLine();
if (s == String.Empty)
{
break;
}
else
{
prs.Platforms.Add(s);
}
}
colItems.Add(prs);
}
strData.Close();
}

. ,
, . , .
.

?

. , .
, , Web-. .

21


. Silverlight-,
.
, .
, "",
, . , " ".
, ,
, Web-.
Web- , , . Web ,
, , , .
Silverlight Web-. .


Web-
, ,
, . 7 , , , 8.
.

21.

365

.
 ,

, .
Silverlight .
 , , -

Web-, .
, .
, ,
.
, . ,
,
!..


, . ,
, - Web, , !
?

WebClient
WebClient.
, .
WebClient Web. , , .
, .
 WebClient, -

C#-. , .
 WebClient Web-

. .
, ,
Web-.
Web-, , . Windows Microsoft

366

VI. Web-

Internet Information Services. Windows.


, Web,
(-); Web- . ,
Web-, .
, - , , , image.jpg Web -.
, . ( , Web-, 1.)
Visual Web Developer 2008 RemoteImage.
"" Image
imgImage. ( 7, Image
.) , .


, , .
Loaded .
WebClient.
new. .
WebClient wclImage = new WebClient();

OpenReadAsync WebClient.
:
OpenReadAsync(<- >[, < >])

-
Uri. 7.
.
Object,
.
wclImage.OpenReadAsync(new Uri("image.jpg", UriKind.Relative));

OpenReadAsync
- .
.

21.

367

. , OpenReadAsync.
, .
, , .
OpenReadAsync .
, image.jpg , imgImage?


WebClient OpenReadCompleted.
.
OpenReadCompleted . Object ,
. OpenReadCompletedEventArgs,
.
, Silverlight
. . .
OpenReadCompletedEventArgs Result.
Stream ,
. , 20, .
Image. ,
.
1. BitmapImage, ,
, , OpenReadCompleted. (
BitmapImage 7.)
2. , SetSource
BitmapImage.
Stream .
3. Source Image.
. .
OpenReadCompleted,
WebClient.

368

VI. Web-

private void wclImage_OpenReadCompleted(object sender,


OpenReadCompletedEventArgs e)
{
System.Windows.Media.Imaging.BitmapImage bimImage = new
System.Windows.Media.Imaging.BitmapImage();
bimImage.SetSource(e.Result);
imgImage.Source = bimImage;
}

7, BitmapImage,
Uri, - . ,
,
.
Loaded ,
, ( ):
WebClient wclImage = new WebClient();
wclImage.OpenReadCompleted += wclImage_OpenReadCompleted;
wclImage.OpenReadAsync(new Uri("image.jpg", UriKind.Relative));

WebClient, ,
OpenReadCompleted.
, , Build
< > Build. ,
, Bin/Debug
Web- ( 4). Web-, ,
image.jpg ( ). Web- - Web-; <- Web>/TestPage.html. ,
Web- .
, OpenReadAsync Object. OpenReadCompleted UserState OpenReadCompletedEventArgs.
Object.

21.

369

WebClient

DownloadProgressChanged.

, .
DownloadProcessCompleted
. , , Object
, .
DownloadProcessChangedEventArgs,
.
DownloadProcessChangedEventArgs ProgressPercentage. 0 100,
.
( ProgressBar;
6),
. prbImage.
DownloadProcessChanged, WebClient.
private void wclImage_DownloadProgressChanged(object sender,
DownloadProgressChangedEventArgs e)
{
prbImage.Value = e.ProgressPercentage;
}

Loaded , , ,
DownloadProcessCompleted WebClient ( ).
WebClient wclImage = new WebClient();
wclImage.OpenReadCompleted += wclImage_OpenReadCompleted;
wclImage.DownloadProgressChanged += wclImage_DownloadProgressChanged;
wclImage.OpenReadAsync(new Uri("image.jpg", UriKind.Relative));

, , Web-,
. Web-
. (,
, , ...)

370

VI. Web-


WebClient .
CancelAsync,
.

OpenReadCompleted. , , , . Cancelled OpenReadCompletedEventArgs.
( , .) ,
true, false.
private void wclImage_OpenReadCompleted(object sender,
OpenReadCompletedEventArgs e)
{
if (!(e.Cancelled))
{
System.Windows.Media.Imaging.BitmapImage bimImage = new
System.Windows.Media.Imaging.BitmapImage();
bimImage.SetSource(e.Result);
imgImage.Source = bimImage;
}
}

, , ,
.


.
, , Web-
!..

OpenReadCompleted. ,
...
, , Error OpenReadCompletedEventArgs. , Exception , . ( 12.)
, Error
null.

21.

371

private void wclImage_OpenReadCompleted(object sender,


OpenReadCompletedEventArgs e)
{
if ((!(e.Cancelled)) && (e.Error == null))
{
System.Windows.Media.Imaging.BitmapImage bimImage = new
System.Windows.Media.Imaging.BitmapImage();
bimImage.SetSource(e.Result);
imgImage.Source = bimImage;
}
}

OpenReadCompleted ,
.



, - Web-.
:
 Web- , ;
 , -
;
 .
, - ,
, , picturelist.txt.
- ;
-.
Visual Web Developer 2008 ImageViewer.
C#-, ,
ImageViewer Picture.
.
, Picture INotifyPropertyChanged
( . 13),
,
.
public class Picture : System.ComponentModel.INotifyPropertyChanged
{
private System.Windows.Media.Imaging.BitmapImage fSource;

372

VI. Web-

public event System.ComponentModel.PropertyChangedEventHandler


PropertyChanged;
public System.Windows.Media.Imaging.BitmapImage Source
{
get
{
return fSource;
}
set
{
fSource = value;
NotifyPropertyChanged("Source");
}
}
public Picture(string url)
{
WebClient wclPicture = new WebClient();
wclPicture.OpenReadCompleted += Picture_OpenReadCompleted;
wclPicture.OpenReadAsync(new Uri(url, UriKind.RelativeOrAbsolute));
}
private void Picture_OpenReadCompleted(object sender,
OpenReadCompletedEventArgs e)
{
if ((!(e.Cancelled)) && (e.Error == null))
{
System.Windows.Media.Imaging.BitmapImage bimImage = new
System.Windows.Media.Imaging.BitmapImage();
bimImage.SetSource(e.Result);
Source = bimImage;
}
}
public void NotifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new
System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}

Picture Source BitmapImage,


. , .

21.

373

.
Picture
, - .
OpenReadAsync.
,
OpenReadCompleted. ,
, Source
Picture. PropertyChanges,
INotifyPropertyChanged , .
lstPictures.
, Image, Source Picture. ""
.
<ListBox x:Name="lstPictures" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<Image Source="{Binding Path=Source}"></Image>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

-
. Loaded
. :
WebClient wclList = new WebClient();
wclList.OpenReadCompleted += wclList_OpenReadCompleted;
wclList.OpenReadAsync(new Uri("picturelist.txt", UriKind.Relative));

.
,
OpenReadCompleted. .
if ((!(e.Cancelled)) && (e.Error == null))
{
System.IO.StreamReader strPictures = new
System.IO.StreamReader(e.Result);
System.Collections.ObjectModel.ObservableCollection<Picture>
colPictures = new
System.Collections.ObjectModel.ObservableCollection<Picture>();
while (!(strPictures.EndOfStream))
{
Picture pct = new Picture(strPictures.ReadLine());

374

VI. Web-

colPictures.Add(pct);
}
lstPictures.DataContext = colPictures;
strPictures.Close();
}

picturelist.txt , 20,
Picture .
lstPictures .
. .
.
, , , ,
Web-. picturelist.txt, , ,
Web-. ,
, Web- Web Web-. , .

?
, Silverlight , . : ,
, .
. , Web-.
Silverlight Visual Web Developer 2008
.

22

Web-
, ,
. - , Web-.
, ,
. , , Web-,
( 1).
, ,
, .
; , , , . Web-, Microsoft
.
Web- .

Web-
Web- , , ,
Web-
, (, ).
Web- ,
, , , , .

376

VI. Web-

Microsoft Web- .NET. 1, "" Silverlight, , .NET- ,


Silverlight-. .NET, ""
Silverlight, "", . Web-.
Web- Visual Web Developer 2008. ( , Visual Web Developer 2008 Web- ,
Web-; Silverlight-
.) C#,
. .NET, , .
.
,
.
.


,
. , , . . ?
, , , .
, ,
, , .
.
, . , ,
,
.
. -, , . -,
, . "" , .
; , , .
, "" .

22. Web-

377

.
, , . .
, . , ,
. ,
,
. ,
, .
C#,
. , C#: , , , ,
. ; .
.
- . ,
.
. , .
.

,
. ,
. ,
;
.

GridDemo, , .
, 20,
.
, ,
Web- Silverlight-.
 persons .
 Silverlight- PersonsClient
persons,

378

VI. Web-

 Web- PersonsWS "" -

persons Silverlight- PersonsClient.


.

Web-

. , .


Visual Web Developer 2008 "" Microsoft SQL Server 2008. Visual
Web Developer 2008 SQL Server 2008
.


, persons.
Visual Web Developer 2008 Database Explorer
(. 22.1). , Database
Explorer View <Ctrl>+<Alt>+<S>,
.

. 22.1. Database Explorer

22. Web-

379

, , Visual Web Developer 2008.


"" Data Connections ,
.
Database Explorer
Add Connection.
Add Connection (. 22.2).

. 22.2. Add Connection

, Data source
Microsoft SQL Server Database File (SqlClient). , Change. Data source Change Data Source (. 22.3) Microsoft
SQL Server Database File OK.
Database file name (new or existing) Add Connection . , ,
Browse

Windows. , persons.

380

VI. Web-

. 22.3. Change Data Source

OK. Visual Web Developer 2008 , , . .


Visual Web Developer 2008
Database Explorer.
"" "" Data Connections,
. 22.1.
"". "",
, , "" Tables. , . . .


, .
persons . ,
. . , , . 22.1.
22.1. persons persons


SQL Server 2008

id

int

22. Web-

381
22.1 ()


SQL Server 2008

nvarchar

20

n1

nvarchar

20

n2

nvarchar

20

age

smallint

int SQL Server 2008 ,


nvarchar , smallint .
platforms , . . 22.2.
22.2. platforms persons


SQL Server 2008

id

int

person

int

name

nvarchar

25

person? ...
,
Person, , Platforms
. , .
, , SQL
Server 2008, . . (
platforms), ,
. , (
person; id persons). , ,

382

VI. Web-

,
, person
. .
.
Database Explorer "", ,
"" Tables, .

Add New Table. Visual Web Developer 2008 ,
(. 22.4).

. 22.4. ,

. , , .
, , .
.
.
 Column Name .
 Data Type SQL Server 2008.
nvarchar(< >), ,
nvarchar(20) 20 .

22. Web-

383

 Allow Nulls. , , ,

( null). , ( ).
, persons.
(. . 22.1). Allow Nulls
, n2 ().
. ,
, .
id ""
Identity Specification. (Is Identity). ,
;
Yes.
id . , . Set Primary Key ( ) , Set Primary Key Table Designer . , ,
.
. Visual Web Developer 2008
Choose Name,
. persons Enter a name for the table
OK. , "" Tables
Database Explorer persons,
.
persons.
platforms.


. persons
: , ,
. platforms , .
person, id
.

384

VI. Web-

. persons, , , ,
platforms, , ,
. ( , 14, LINQ.)
SQL Server 2008 "". ,
persons platforms , .
platforms. "" Tables
Database Explorer Open Table Definition. Visual Web Developer 2008 .
Relationships ( )
Relationships Table
Designer. Foreign Key
Relationships (. 22.5).

. 22.5. Foreign Key Relationships

Selected Relationship
; , , . , Add. -

22. Web-

385

, Selected Relationship
. , , , Tables And
Columns Specification , . Tables and
Columns (. 22.6).

. 22.6. Tables and Columns

Primary key table


persons. , , , , id. , ,
person. OK.
Foreign Key Relationships, ""
INSERT And UPDATE Specification , . Delete Rule "" , , Cascade. SQL Server 2008

.
Cascade Update Rule
"". SQL Server 2008 ,

386

VI. Web-

id
person . .
, Close, Foreign Key
Relationships. platforms.
Visual Web Developer 2008 , ,
, ; Yes, .


. , .
persons.
"" Tables Database Explorer
Show Table
Data. Visual Web Developer 2008 , (. 22.7).

. 22.7. ,

, .
- ,
. -.
- ;
null.
. .

22. Web-

387

<Enter> -.
, <Esc>.
persons . platforms,
person ,
id persons.
.

Web-
Web-, ""
. .

Web-
Web- ,
. 3,
"" ;
.
:
 PersonsClient;
 Web- PersonsSite, Web-
PersonsWS. Web- ,
Web-.

Web-, Web-.
New Project File <Ctrl>+<Shift>+<N>. Project types
New Project (. . 3.6) "" Visual C#
Web. Templates ASP.NET Web Application.
Name Web- PersonsSite.
, Create directory for
solution. Visual Web Developer 2008
, . PersonsSolution Solution Name.
OK. .

388

VI. Web-


C#. ,
C#-.
""
PersonsSite Solution Explorer
New Item Add. Add
New Item (. . 18.1). "" Visual C#
Categories Data, Templates ADO.NET
Entity Data Model. Name
Persons. Add.
Entity Data Model Wizard, "" (. 22.8). What should the model
contain? Generate from database, Visual Web Developer 2008
,
Next.

. 22.8. Entity Data Model Wizard ( )

22. Web-

389

"" (. 22.9)
Which data connection should your application use to connect to the
database? persons. (
; SQL Server 2008
mdf.) Next.

. 22.9. Entity Data Model Wizard ( )

"" (. 22.10) Which database objects do you want to include in your model?.
"" ;
"" , .
"" Tables , .
Finish.
Visual Web Developer 2008
(. 22.11).
, : (persons platforms),
, , , -

390

VI. Web-

. 22.10. Entity Data Model Wizard ( )

; (id, f, n1, n2,


age persons id name platforms),
; .
, , persons platforms. ,
, . platforms, , persons, , .
, Visual Web Developer 2008 ,
.

Web-
Web-.
""
PersonsSite Solution Explorer New Item

22. Web-

391

. 22.11. ,

Add. "" Visual C# Categories Add New


Item Web, Templates ADO.NET Data
Service. Name Web- PersonsWS.
Add.
Visual Web Developer 2008 Web- , C#-. :
public class PersonsWS : DataService
< /* TODO: put your data source class name here */ >

, PersonsWS Web-.
DataService, Web-.
, , .
; <

392

VI. Web-

>Entities.
personsEntities.

Entity Data Model Wizard (. . 22.9)


, .

:
public class PersonsWS : DataService<personsEntities>

, PersonsWS InitializeService.
Web- , ,
, , ,
:
. ,
, InitializeService:
config.SetEntitySetAccessRule("persons", EntitySetRights.All);
config.SetEntitySetAccessRule("platforms", EntitySetRights.All);

config InitializeService
IDataServiceConfiguration.
SetEntitySetAccessRule .
, EntitySetRights.
All ( , ) .
. Web-
Build < > Build.
Solution Explorer, ,
Web- svc. Web- Microsoft .NET.
, C#- Web-
.


Web- . .

Silverlight-,
Web-
Visual Web Developer 2008 PersonsClient.
New Project

22. Web-

393

Solution. Add to Solution,


, (. .
PersonsSolution).
OK New Project,
New Silverlight Application. ,
. . 22.12.

. 22.12. New Silverlight Application


( Silverlight- Web-, Web-)

, Host the Silverlight application in a new or


existing Web site in the solution. Visual Web Developer 2008
Web-.
, .
, Add a test page that references the
application Make it the start page.
Silverlight- Web.
OK. .
: grdPersons grdPlatforms , -

394

VI. Web-

.
. : btnAddPerson
, btnRemovePerson ,
btnAddPlatform btnRemovePlatform
.

Silverlight-
Web-
Web-.
Visual Web Developer 2008 ,
Web- . ,
,
.
Solution Explorer ""
PersonsClient, .

Add Service Reference. Add Service Reference (. 22.13).

. 22.13. Add Service Reference

22. Web-

395

Address - Web-,
Go. Web-
Web-, ,
Silverlight-, Discover. .
Visual Web Developer 2008 Web-
Services. , Web- . ""
, Web-, "".
Namespace ,
Visual Web Developer 2008 Web . Persons.
, OK. Visual
Web Developer 2008 .
Persons. persons platforms. persons id, f,
n1, n2, age platforms, platforms id, persons name.
, "" ,
Web-. , Web-
, .
Persons personsEntities.
Web-, , ( ) () . Silverlight personsEntities Web-.
personsEntities DataServiceContext. , Web. .

Web-
, Web-,
. Web- ,
. .
, .
,

396

VI. Web-

.
.


(
( platforms). .

ObservableCollection.
persons),

private System.Collections.ObjectModel.ObservableCollection
<Persons.persons> colPersons;
private System.Collections.ObjectModel.ObservableCollection
<Persons.platforms> colPlatforms;

, Web-
personsEntities.
private Persons.personsEntities svcPersons;

, persons, platforms personsEntities


Persons.

.
colPersons = new System.Collections.ObjectModel.ObservableCollection
<Persons.persons>();
colPlatforms = new System.Collections.ObjectModel.ObservableCollection
<Persons.platforms>();
grdPersons.DataContext = colPersons;
grdPlatforms.DataContext = colPlatforms;

Web-.
, DataServiceContext,
Uri, Web-. , Web-
svc, PersonsWS.svc. , ,
Web-, :
svcPersons = new Persons.personsEntities(new Uri("PersonsWS.svc",
UriKind.Relative));

Web- .
Loaded . .
, Web-, BeginExecute, DataServiceContext, , . -

22. Web-

397

, Silverlight! , , ,
.
BeginExecute :
BeginExecute< >(< Web->,
<, >, < >)

, .
, Web.
Uri, Web-, .
, .
- , .
Object, . . . , null.
, Loaded .
:
svcPersons.BeginExecute<Persons.persons>(new Uri("persons",
UriKind.Relative), svcPersons_QueryComplete, null);

svcPersons_QueryComplete,
. . -,
. -, IAsyncResult, . ,
Web- .
IAsyncResult AsyncState.
,
BeginExecute, Object.
svcPersons_QueryComplete .
DataServiceContext EndExecute.
IAsyncResult,
. svcPersons_QueryComplete .

398

VI. Web-

EndExecute IEnumerable.
EndExecute,
IEnumerable , . ,
.
svcPersons_QueryComplete:
private void svcPersons_QueryComplete(IAsyncResult result)
{
IEnumerable<Persons.persons> colResult =
svcPersons.EndExecute<Persons.persons>(result);
colPersons.Clear();
foreach (Persons.persons prs in colResult)
{
colPersons.Add(prs);
}
}

,
.

Silverlight-,
Web-
.
- .
Solution Explorer "", Web- PersonsSite, Web-
Web-.
Set as a StartUp Project.
"" PersonsSite .
, , .
Start Debugging ( ) , Start Debugging Debug <F5>. , , Web- Web-
, Web. .
Web- Visual Web Developer 2008
Web-. Web-

22. Web-

399

, Web-,
.
Web- Visual Web Developer 2008
.
Silverlight-
Web-.
Web-
(. ).
. ,
Web- Web-.

Web- . !
,
, Web-.
Web- Web-
Web-, Web- .

, Web- Visual Web Developer 2008


, , .
, ;
OK. Web-; .

LINQ- Web-
LINQ- . ( LINQ
14.)
, , .
DataServiceQuery.

;
DataServiceContext.
DataServiceQuery System.Data.Services.
Client. ,
, .
DataServiceQuery ,
. ,
.

400

VI. Web-

.
.
private System.Data.Services.Client.DataServiceQuery<Persons.persons>
qryPersons;

. 14,
from, , . ?
!
CreateQuery,
DataServiceContext
Web-. Web-, .
CreateQuery ,
,
.
CreateQuery DataServiceQuery.
LINQ- .
Web- ,
, .

DataServiceQuery, . . .
, BeginExecute
DataServiceQuery. :
BeginExecute(<, >,
< >)

, DataServiceContext,
: Web-.
,
DataServiceQuery.
, , Loaded ,
.
qryPersons =
(System.Data.Services.Client.DataServiceQuery<Persons.persons>)
from person in svcPersons.CreateQuery<Persons.persons>("persons")
orderby person.f
select person;
qryPersons.BeginExecute(svcPersons_QueryComplete, null);

22. Web-

401

svcPersons_QueryComplete, .
,
IEnumerable<Persons.persons> colResult =
svcPersons.EndExecute<Persons.persons>(result);

:
IEnumerable<Persons.persons> colResult = qryPersons.EndExecute(result);

, , EndExecute DataServiceQuery, .
DataServiceContext , .
. , , .
LINQ- Web- . :
qryPersons =
(System.Data.Services.Client.DataServiceQuery<Persons.persons>)
from person in svcPersons.CreateQuery<Persons.persons>("persons")
where person.age > 30
orderby person.f
select person;

30 .


,
... ?
persons, Visual Web Developer 2008
Web-, platforms. platforms, . . ,
. , ,
13.
- , . , Web ,
. .

grdPersons.

SelectionChanged
.

402

VI. Web-

BeginLoadProperty
DataServiceContext -. :
BeginLoadProperty(<,
>, < >, <, >,
< >)

, . . , , , .
, SelectionChanged
grdPersons :
svcPersons.BeginLoadProperty(grdPersons.SelectedItem as Persons.persons,
"platforms", svcPersons_LoadPropertyCompleted, null);

platforms ,
grdPersons. svcPersons_LoadPropertyCompleted.
,
,
: .
BeginLoadProperty,
BeginExecute.

, EndLoadProperty
DataServiceContext -. IAsyncResult,
( EndExecute).
QueryOperationResponse.
QueryOperationResponse "" Web-. IEnumerable; , , .
svcPersons_LoadPropertyCompleted.
private void svcPersons_LoadPropertyCompleted(IAsyncResult result)
{
System.Data.Services.Client.QueryOperationResponse colResult =
svcPersons.EndLoadProperty(result);
colPlatforms.Clear();
foreach (Persons.platforms pls in colResult)

22. Web-

403

{
colPlatforms.Add(pls);
}
}

, svcPersons_QueryComplete.
.

,

, .
...
, 19, . txtF,
txtN1, txtN2 txtAge, , ,
. AddPerson.
Click btnAddPerson .
:
AddPerson wndAdd = new AddPerson();
wndAdd.Closed += wndAddPerson_Closed;
wndAdd.Show();

19. , Closed - wndAddPerson .


wndAddPerson :
1. persons.
2. , .
3. , .
4. Web-.
. ...
Web-
AddObject, DataServiceContext . :
AddObject(< >, < >)

Web, , . .

404

VI. Web-

. Web- .
BeginSaveChanges DataServiceContext .
:
BeginSaveChanges(<, >,
< >)

, , . EndSaveChanges, DataServiceContext
.
IAsyncResult, .
, ,
.
,
:
private void wndAddPerson_Closed(object sender, EventArgs e)
{
AddPerson wndAdd = sender as AddPerson;
if (wndAdd.DialogResult == true)
{
Persons.persons prs = new Persons.persons();
short iAge;
prs.f = wndAdd.txtF.Text;
prs.n1 = wndAdd.txtN1.Text;
prs.n2 = wndAdd.txtN2.Text;
if (short.TryParse(wndAdd.txtAge.Text, out iAge))
{
prs.age = iAge;
}
colPersons.Add(prs);
svcPersons.AddObject("persons", prs);
svcPersons.BeginSaveChanges (svcPersons_SaveChangesCompleted, null);
}
}
private void svcPersons_SaveChangesCompleted(IAsyncResult result)
{
svcPersons.EndSaveChanges(result);
}

. DataGrid ,

22. Web-

405

. .
DataGrid RowEditEnded, , , <Enter>.
.
Web-
UpdateObject DataServiceContext .
. .
UpdateObject
. BeginSaveChanges.
RowEditEnded grdPersons:
svcPersons.UpdateObject(grdPersons.SelectedItem);
svcPersons.BeginSaveChanges(svcPersons_SaveChangesCompleted, null);

.
. Web-,

.
Web-
DeleteObject DataServiceContext -. .
DeleteObject
BeginSaveChanges.
Click btnRemovePerson
, :
if (MessageBox.Show(" ?", "",
MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
Persons.persons prs = grdPersons.SelectedItem as Persons.persons;
colPersons.Remove(prs);
svcPersons.DeleteObject(prs);
svcPersons.BeginSaveChanges(svcPersons_SaveChangesCompleted, null);
}

406

VI. Web-

, , -.
( - 19.) , K, .

, , ,
. ,
...



.
.
, platforms,
, , .
?
persons platforms,
platforms. platforms
persons, , , . . persons. ,
platforms
persons . .
, , Web- .
Web-
.
, . AddObject Web.
svcPersons.AddObject("platforms", pls);

platforms Web- pls.


. -

22. Web-

407

AddLink, DataServiceContext
.
:
AddLink(< >,
< ,
 >,
< >)

,
.
, , .
.
svcPersons.AddLink(currentPerson, "platforms", pls);

pls currentPerson. platforms.


""
. SetLink DataServiceContext . :
AddLink(< >,
< ,
 >,
< >)


, .
, , .
,
.
svcPersons.SetLink(pls, "persons", currentPerson);

currentPerson
pls.
persons.
,
Web-.

408

VI. Web-

, . , :
1. platforms.
2. , .
3. , , .
4. .
5. Web-.
6. Web-.
.
txtName,
. AddPlatform.
Click btnAddPlatform . :
AddPlatform wndAdd = new AddPlatform();
wndAdd.Closed += wndAddPlatform_Closed;
wndAdd.Show();

.
Closed AddPlatform:
private void wndAddPlatform_Closed(object sender, EventArgs e)
{
AddPlatform wndAdd = sender as AddPlatform;
if (wndAdd.DialogResult == true)
{
Persons.platforms pls = new Persons.platforms();
pls.name = wndAdd.txtName.Text;
colPlatforms.Add(pls);
Persons.persons currentPerson = grdPersons.SelectedItem as
Persons.persons;
currentPerson.platforms.Add(pls);
pls.persons = currentPerson;
svcPersons.AddObject("platforms", pls);
svcPersons.AddLink(currentPerson, "platforms", pls);
svcPersons.SetLink(pls, "persons", currentPerson);
svcPersons.BeginSaveChanges(svcPersons_SaveChangesCompleted, null);
}
}

22. Web-

409

, . , ,
.

.

?
Silverlight-, Web-. .NET Visual Web
Developer 2008.
, . "", Silverlight. .

410

VI. Web-

VII


23.

24.

Silverlight-

23


... !
, Web-, , Web- , ,
. ,
, .
...
, , .
. ,
.
Silverlight, . , ,

.



, 13.
. .
C#-.
, , DataContext,
. .
. MultiPage, 18, -

414

VII.

. , , , ,
.
, . 18. ,
...



Windows- ,
, , . Silverlight- .

ToolTipService.ToolTip, . .
<Button x:Name="btnAddPerson" Content="" . . .
ToolTipService.ToolTip=" " . . .></Button>


22.

btnAddPerson

PersonsClient,

, ToolTipService.ToolTip
ToolTip. , .
, Content.
Object , . , , ,
, .
<Button x:Name="btnAddPerson" Content="" . . .>
<ToolTipService.ToolTip>
<ToolTip>
<ToolTip.Content>
<StackPanel>
<Image Source="add.jpg"></Image>
<TextBlock Text=" "></TextBlock>
</StackPanel>

23.

415

</ToolTip.Content>
</ToolTip>
</ToolTipService.ToolTip>
</Button>

, , "".
HorizontalOffset VerticalOffset
, , .
0.
IsOpen true,
, false .
, , .

IsOpen C#-!

ToolTip ActualHeight, ActualWidth,


FontFamily,
FontSize,
FontStretch,
FontStyle,
FontWeight,
Height,
HorizontalAlignment, IsEnabled, Margin, MaxHeight, MaxWidth, MinHeight,
MinWidth, Name, Padding, TabIndex, VerticalAlignment, Visibility Width,
, (. 15 16).
<ToolTipService.ToolTip>
<ToolTip Content=" " FontSize="18"
FontStyle="Italic" Foreground="Blue"></ToolTip>
</ToolTipService.ToolTip>

18 ,
.
ToolTip , . Opened
, Closed .


1 , Silverlight-,
Web-, Web-. Web-, , , "" .

416

VII.

Silverlight , .
Silverlight- .
...
 , Silverlight-

.
,
Web-,
Web-.


( Silverlight- Web-),
<Esc> <Alt>+<F4>. ,
.
 , ,

, .
, , Click .
, , , .


OpenFileDialog
,
.
( 20.)

SaveFileDialog.

, ? ...
1. , Silverlight-
. Visual Web
Developer 2008
Application. Application ,
, .
2. , Application
Current.
, Application.
3. Application Host. SilverlightHost,
Silverlight,
.

23.

417

4. SilverlightHost Content. Content, Web-, Silverlight-.


5. Content IsFullScreen. true
,
false .
,
:
Application.Current.Host.Content.IsFullScreen = true;


Current Application,
Silverlight ( Host),
Web- ( Content),
(
IsFullScreen).
PersonsClient,
22, , btnFullScreen.

. Click .
:
if (Application.Current.Host.Content.IsFullScreen)
{
Application.Current.Host.Content.IsFullScreen = false;
btnFullScreen.Content = " ";
}
else
{
Application.Current.Host.Content.IsFullScreen = true;
btnFullScreen.Content = " ";
}

, ,
,
btnFullScreen.
Content FullScreenChanged, .

418

VII.



, . ,
. ,
.
Silverlight . ( 20.) ,
.
,
.
"" IsolatedStorageSettings.
,
, ,
, .
IsolatedStorageSettings System.IO.
IsolatedStorage. ,
, .
, IsolatedStorageSettings,
( ). Silverlight
, , .
, .

ApplicationSettings IsolatedStorageSettings.
, , .

.
.
private System.IO.IsolatedStorage.IsolatedStorageSettings iseOptions =
System.IO.IsolatedStorage.IsolatedStorageSettings.ApplicationSettings;

, . . IsolatedStorageSettings,
. ( 11.) , -

23.

419

.
.
IsolatedStorageSettings ""
.
,
Add.
Add(<>, <>)

,
, .
iseOptions.Add("width", 800);

800 width.
,
:
LayoutRoot.Width = iseOptions["width"];

:
iseOptions["width"] = 1024;

Contains , , .
true, , false .
if (!(iseOptions.Contains("width")))
{
iseOptions.Add("width", LayoutRoot.Width);
}

, width, ,
, .
if (iseOptions.Contains("width"))
{
LayoutRoot.Width = iseOptions["width"];
}

, width, ,
, .

, , .
, , .

420

VII.

Remove.
true, ,
false .
iseOptions.Remove("width");

Count
.
Clear .
.
,
. .
Save IsolatedStorageSettings, .

?
, ,
, ...
Silverlight-.
, ...

24

Silverlight-
Silverlight-. Silverlight, XAML C#
Visual Web Developer 2008.
. .
,
.
Silverlight. ,
, ,
Web-.
Web-
, Windows-.
-, Silverlight !

Silverlight-.

Silverlight-
, .
,
- .
"" , .
, "". ,
: , . -

422

VII.

() , ,
, ()
. ,
.
, "", .
. , 2.0 ,
1.0.
, - . - ;
. ,
" ".
, . ,
.
 -

. , .
 .

, .
, .

.
, . ? .


Visual Web Developer 2008
, . .
Visual Web Developer
: . , . , , .

24. Silverlight-

423

, . .
Configuration Manager Build. Configuration Manager (. 24.1).

. 24.1. Configuration Manager

, , Active solution configuration . Debug,


Release. - .
! Configuration Manager Close.
Visual Web Developer 2008 .
Build < > Build. .

,
. .
? ? 4 , .
.

424

VII.

, , Bin.
: Debug Release. .
,
Release.
, , ( ) ZIP,
( Web-, ). xap , .
Web-.
TestPage.html.
, "" , .
Windows. .
, .
, .
, Visual Web
Developer 2008 , . , GridDemo
GridDemo.
, GridDemo
GridDemo.dll. : , ,
, .
, , . , GridDemo (
, )
System.ComponentModel.DataAnnotations.dll, System.Windows.Controls.Data.dll,
System.Windows.Controls.Data.Input.dll,
System.Windows.Controls.dll

System.Windows.Data.dll. ,
.
! , , .
.
,
. Visual Web Developer 2008
ZIP,
. .

24. Silverlight-

425

? , - .
, ,
.
, , ,
.
: de, es,
fr . ,
. ,
de, es,
fr . .
? , . (
.) - :
, Silverlight 3
Microsoft, , ...
! 8 ,
.

8.
,
, . ""
"" , .
, , Silverlight-:
 ;
 Web-, (
Web-, Visual Web Developer 2008,
Web-, );
 ZIP- , ;
 "" ,
,
;
 .

426

VII.

Web- . !


Silverlight-.
? ?
! Solution Explorer "" Properties
. < >
Properties Project. , "" ;
.
Silverlight (. 24.2). ,
; , , .

. 24.2. Silverlight ,

Application ,
, ,

24. Silverlight-

427

, (
). ( )
.
, .
Assembly Information. , Assembly Information (. 24.3).

. 24.3. Assembly Information

, , .
 Title ( ).
 Description .
 Company .
 Product ( -

).
 Copyright .
 Trademark , .

: Assembly Version File


Version. , ,
; , .

428

VII.

( ):
 ,
;
 , -

;
 ,

;
 , .
GUID ,
Visual Web Developer 2008
. .
Neutral Language , . , (None) ( ), Russian Russian (Russia) ( ).
. Silverlight.

, OK, . ,
Cancel.
Silverlight ,
. ? , Silverlight build options!
Xap file name . , ...
Reduce XAP size by using application library caching
! , Visual Web Developer 2008 ZIP-, .
, .
, .
, , .

24. Silverlight-

429

Silverlight-
Web-
Silverlight- Web, Visual Web Developer 2008. Web-
HTML-,
Silverlight.
Silverlight- Web, HTML- .
.
:
<object width="< >" height="< >"
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2" >
<param name="source" value="<- >"/>
<a href="http://go.microsoft.com/fwlink/?LinkID=149156"
style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181"
alt="Get Microsoft Silverlight"
style="border-style: none"/>
</a>
</object>

HTML- <OBJECT>, , ,
Silverlight- Web-. width height .
<OBJECT> <PARAM>. value - , . , name source.

, Silverlight-,
, Web-, .

<OBJECT> <A>. Web-


,
Silverlight, Web- -. , Web-

430

VII.

Microsoft, Silverlight .

Silverlight-
! Silverlight-, Web-.
 Silverlight- ,
Windows-.
 Silverlight- ,
Windows-.
(Start) .
Silverlight- Web-, .
 Silverlight-, , .
 Silverlight- Silverlight , , , ,
Web-, ,
. , . Silverlight-.
Silverlight- ,
. .

Silverlight-
, . ( , .)
Silverlight, .
Enable running application out of the browser, Silverlight build options. , .
.
Out-of-Browser Settings,
Enable running application out of the browser.
Out-of-Browser Settings (. 24.4).
Windows Title ,
Silverlight-.
.

24. Silverlight-

431

. 24.4. Out-of-Browser Settings

Width Height , , . ,
800600 .
Shortcut name , . < > Application.
Download description ,
. ,
Silverlight-.
16 x 16 Icon, 32 x 32 Icon, 48 x 48 Icon 128 x 128 Icon 1616, 3232, 4848
128128 . . , , -

432

VII.


Windows.
Use GPU Acceleration Silverlight
. ,
.
, OK, . Cancel
.
! .


Silverlight-
Silverlight- Web, . Install < >
onto this computer. (
Shortcut name Out-of-Browser Settings (. . 24.4).)
Install application (. 24.5),
.

. 24.5. Install application

Start menu Desktop


Silverlight , ,
(Start) .
OK. Cancel.
. , .

24. Silverlight-

433

,
(Start) . ,
Windows-,
( ) <Alt>+<F4>.
Silverlight-, Web- Web-, , - Web- Remove this application. Silverlight
-, , ;
.
Silverlight-.
Silverlight!

434

VII.


- Microsoft Silverlight 3. , XAML C#,
Microsoft Visual Web Developer 2008 Express Edition,
Web-.
,
. .
. , - , - , - .
,
Silverlight 3 - . ...
, .
 Silverlight:

MSIL-, , , , .
 : , (

, ;
Silverlight),
.
 .
"" Web-, Silverlight
.
 : , , .
,
.
.
 .
 -

436

 , . -

- , .
 .
 Silverlight- Silverlight.
 Silverlight- Web- Web, , Web Silverlight-.
 , " "...
, ... , , ,
. , , , , . .
? ,
( ). , . ,
, , .
.
. 1 - Silverlight.
1. -
-

http://www.silverlight.net/

Microsoft, Silverlight.
, ,

http://msdn.microsoft.com
/ru-ru/default.aspx

MSDN (MicroSoft Developers Network).


,
. ,
Microsoft

http://www.microsoft.com/
visualstudio/en-us/default.mspx

"" Microsoft,
Visual Studio

http://www.microsoft.com
/silverlight/default.aspx

"" Microsoft,
Silverlight. ,
, ...

, , Silverlight.
. 1 "", "".
, !
Silverlight-!


A
Abs() 180
Abstract 182, 184
AcceptsReturn 100
Acos() 180
ActualHeight 97
ActualWidth 97
Add() 194, 202, 207, 419
AddDays() 194
AddHours() 194
AddLink() 407
AddMilliseconds() 194
AddMinutes() 194
AddMonths() 194
AddObject() 403
AddSeconds() 194
AddYears() 194
AlignmentX 292
AlignmentY 292
Angle 301
AngleX 302
AngleY 302
Application 416
ApplicationSettings 418
ArcSegment 281
ArgumentException 215
ArgumentNullException 216
ArgumentOutOfRangeException 216
ArithmeticException 216
ArrayTypeMismatchException 215
Asin() 180
AsyncState 397
Atan() 180

AutoGenerateColumns 243
AutoPlay 125
AutoReverse 311
AvailableFreeSpace 355
Average() 261

B
Background 284
Balance 125
Base 185
Begin() 319
BeginExecute() 396, 400
BeginLoadProperty() 402
BeginSaveChanges() 404
BeginTime 312
BezierSegment 282
Binding 228, 244
BindingMode 229
BitmapImage 122
BlurEffect 298
BlurRadius 298
Border 284
BorderBrush 284
BorderThickness 284
Brush 272
Button 103
By 258, 309

C
Calendar 110
CalendarClosed 111

438

CalendarOpened 111
CancelAsync() 370
Cancelled 370
CanGoBack 327
CanGoForward 327
CanUserReorder 243
CanUserReorderColumns 242
CanUserResize 243
CanUserResizeColumns 242
CanUserSort 243
CanUserSortColumns 243
Canvas 89
Canvas.Left 90
Canvas.Top 90
Canvas.ZIndex 91
Case 157
Catch 217
Ceiling() 180
CellEditingTemplate 244
CellTemplate 244
Center 277, 289
CenterOfRotationX 304
CenterOfRotationY 304
CenterOfRotationZ 304
CenterX 301, 302
CenterY 301, 302
Chars 178
CheckBox 105
Checked 106
Child 284
Children 212, 278, 303, 308
ChildWindow 335
Class 181
Clear() 203, 208, 420
Click 104
ClickMode 104
Clip 295
Close() 337, 352
Closed 338, 415
Color 286, 288
ColorAnimation 309
ColorAnimationUsingKeyFrames 313
ColorKeyFrame 313
ColorKeyFrameCollection 313
ColumnDefinition 87
ColumnDefinitionCollection 87
ColumnDefinitions 87
Columns 243

ComboBox 109
ComboBoxItem 109
Completed 320
Const 189
Contains() 204, 419
ContainsKey() 209
ContainsValue() 209
Content 103, 105, 106, 108, 113, 115,
414, 417
ContentControl 103
Convert() 234
ConvertBack() 234
Converter 235
CornerRadius 284
Cos() 180
Count 202, 207, 420
Count() 261
CreateDirectory() 347
CreateQuery() 400
CultureInfo 234
Current 416
CurrentState 125
CurrentStateChanged 126

D
Data 276
DataContext 240
DataGrid 241
DataGridCheckBoxColumn 243
DataGridColumn 243
DataGridGridLinesVisibility 242
DataGridHeadersVisibility 242
DataGridTemplateColumn 243
DataGridTextColumn 243
DataService 391
DataServiceContext 395, 396
DataServiceQuery 399
DataTemplate 239
Date 193
DatePicker 111
DateTime 193
DateValidation 111
Day 193
DayOfWeek 193
DayOfYear 193
Days 195
Default 157

DefaultExt 360
DefaultIfEmpty() 266
DeleteDirectory() 354
DeleteFile() 354
DeleteObject() 405
Dequeue() 210
Descending 256
DialogResult 337
Dictionary 207
Direction 298
DirectoryExists() 353
DiscreteColorKeyFrame 314
DiscreteDoubleKeyFrame 314
DiscreteObjectKeyFrame 316
DiscretePointKeyFrame 314
DisplayIndex 243
DisplayMemberPath 238
Dispose() 356
DivideByZeroException 216
do 160
Dock 115
DoubleAnimation 309
DoubleAnimationUsingKeyFrames 313
DoubleKeyFrame 313
DoubleKeyFrameCollection 313
DownloadProcessChangedEventArgs 369
DownloadProgressCompleted 369
DropDownClosed 109
DropDownOpened 109
DropShadowEffect 298
Duration 309

E
EasingFunction 312
Effect 298
ElementName 233
Ellipse 273
EllipseGeometry 277
Else 156
EndExecute() 397, 401
EndLoadProperty() 402
EndOfStream 351
EndPoint 276, 287
EndSaveChanges() 404
Enqueue() 210
EntitySetRights 392
Enum 199

439

Epsilon 192
Equals 258
Error 370
Exception 215
Exists 362
Exp() 180

F
Figures 279
File 362
FileAccess 348
FileExists() 353
FileInfo 362
FileMode 348
FileStream 362
Fill 272
FillBehavior 311
FillRule 275
Filter 359
FilterIndex 359
Finally 218
Flash 18
Floor() 180
Focus() 101
FontFamily 95
FontSize 95
FontStretch 95
FontStretches 95
FontStyle 96
FontStyles 96
FontWeight 96
FontWeights 96
For 159
Foreach 165
Foreground 285
Frame 323
FrameworkElement 107
From 253, 309
FullScreenChanged 417

G
Geometry 276
GeometryCollection 278
GeometryGroup 277
GetDirectoryNames() 354
GetFileNames() 353

440

GetUserStoreForApplication() 346
GlobalOffsetX 304
GlobalOffsetY 304
GlobalOffsetZ 304
GoBack() 327
GoForward() 327
GradientOrigin 289
GradientSpreadMethod 289
GradientStop 288
GradientStopCollection 288
GradientStops 288
Grid 82
Grid.Column 87
Grid.ColumnSpan 88
Grid.Row 87
Grid.RowSpan 88
GridLinesVisibility 242
Group 258
GroupName 107

H
HasCloseButton 336
Header 115, 243
HeadersVisibility 242
Height 83, 86
HorizontalAlignment 84
HorizontalOffset 415
HorizontalScrollBarVisibility 100, 114,
242
Host 416
Hour 193
Hours 195
HTML 9, 12
HyperlinkButton 330

I
IAsyncResult 397
IDataServiceConfiguration 392
IEasingFunction 312
IEnumerable 251
If 156
IGrouping 259
Image 121
ImageBrush 292
ImageFailed 122
ImageOpened 122

ImageSource 122, 292


In 165, 253, 258
IncreaseQuotaTo() 355
Indeterminate 106
IndexOf() 178, 204
IndexOutOfRangeException 215
Inline 97
InlineCollecton 97
INotifyCollectionChanged 236
INotifyPropertyChanged 230
Insert() 202
Internal 181, 183
Into 263
InvalidCastException 215
InvalidOperationException 215
IsChecked 105
IsClosed 279
IsDirectionReversed 112
IsEnabled 100
IsFilled 279
IsFullScreen 417
IsIndeterminate 113
IsInfinity() 191
IsLargeArc 281
IsMuted 125
IsNaN() 191
IsNegativeInfinity() 191
IsolatedStorageFile 347
IsolatedStorageFileStream 349
IsolatedStorageSettings 418
IsOpen 415
IsPositiveInfinity() 191
IsReadOnly 100, 242
IsSelected 108
IsTabStop 101
IsThreeState 105, 244
IsTodayHighlighted 110
Item 203, 208
ItemCollection 107
Items 107, 109, 114
ItemsSource 237
ItemTemplate 239
IValueConverter 234

J
Java 19
Join 258

K
Key 209, 259
KeyFrames 313
KeySpline 315
KeyTime 314
KeyValuePair 209

L
LargeChange 112
LastIndexOf() 179, 204
Length 178, 362
Let 264
Line 271
LinearColorKeyFrame 314
LinearDoubleKeyFrame 314
LinearGradientBrush 286
LinearPointKeyFrame 314
LineBreak 98
LineGeometry 276
LineHeight 96
LineSegment 280
LINQ 250
List 201
ListBox 107, 108
ListBoxItem 107
Loaded 91
Loading 328
LocalOffsetX 304
LocalOffsetY 304
LocalOffsetZ 304
Log() 180
Log10() 180
LongCount() 261

M
Margin 83
Math 179
Max() 180, 261
MaxDropDownHeight 109
MaxHeight 83
Maximum 112, 113
MaxLength 99
MaxValue 191, 192
MaxWidth 83
MediaElement 124

441

MediaElementState 125
MediaEnded 126
MediaFailed 126
MediaOpened 126
Message 216
MessageBox 341
MessageBoxButton 341
MessageBoxResult 341
Millisecond 193
Milliseconds 195
Min() 180, 261
MinHeight 83
Minimum 112, 113
Minute 193
Minutes 195
MinValue 191, 192
MinWidth 83
Mode 229
Month 193
MSIL 34

N
Name 97, 362
NaN 192
Navigate() 327
Navigated 328
NavigateUri 330
Navigating 328
NavigationContext 329
NavigationFailed 328
NavigationService 327
NavigationStopped 328
NegativeInfinity 192
NotEmplementedException 235
NotFiniteNumberException 216
Now 193
Null 177
NullReferenceException 215

O
Object 91, 178
ObjectAnimationUsingKeyFrames 316
ObjectKeyFrame 316
ObjectKeyFrameCollection 316
ObservableCollection 236
Offset 288

442

On 258
Opacity 272, 286
OpacityMask 297
Opened 415
OpenFile() 347, 360
OpenFileDialog 361
OpenRead() 362
OpenReadAsync() 366
OpenReadCompleted 367
OpenReadCompletedEventArgs 367
OpenText() 362
Orderby 255
Orientation 89, 112
Out 175, 184
OutOfMemoryException 215
OverflowException 216
Override 184

P
Padding 95
Page 325
Partial 182
Password 103
PasswordBox 103
PasswordChanged 103
PasswordChar 103
Path 228, 276
PathFigure 279
PathFigureCollection 279
PathGeometry 279
PathSegment 279
PathSegmentCollection 279
Pause() 126, 319
Peek() 210, 211
PI 179
PlaneProjection 304
Play() 126
Point 274, 276, 280
Point1 282
Point2 282
Point3 282
PointAnimation 309
PointAnimationUsingKeyFrames 313
PointCollection 274
PointKeyFrame 313
PointKeyFrameCollection 313
Points 274, 280

PolyBezierSegment 282
Polygon 274
Polyline 276
PolyLineSegment 280
PolyQuadraticBezierSegment 283
Pop() 211
Position 126
PositiveInfinity 192
Pow() 180
Private 181, 183
ProgressBar 112
ProgressPercentage 369
Projection 304
Protected 183
Protected internal 183
Public 181, 183
Push() 211

Q
QuadraticBezierSegment 283
QueryOperationResponse 402
QueryString 329
Queue 210
Quota 355

R
RadialGradientBrush 289
RadioButton 106
Radius 298
RadiusX 272, 277, 289
RadiusY 273, 277, 289
ReadLine() 351
Readonly 183
ReadToEnd() 351
Rect 277
Rectangle 272
RectangleGeometry 277
RelativeTransform 299
Remove() 203, 208, 356, 420
RemoveAt() 203
RenderTransform 299
RepeatBehavior 312
ResourceDictionary 227
Resources 227
Result 367
Resume() 319

RotateTransform 301
RotationAngle 281
RotationX 304
RotationY 304
RotationZ 304
Round() 180
RoutedEventArgs 91
RowDefinition 86
RowDefinitionCollection 86
RowDefinitions 86
RowEditEnded 405
Run 97

S
SafeFileName 360
Save() 420
SaveFileDialog 359
ScaleTransform 301
ScaleX 301
ScaleY 301
ScrollBarVisibility 101
ScrollViewer 113
Sealed 181, 185
Second 194
Seconds 195
Seek() 319
SeekAlignedToLastTick() 319
Segments 279
Select 253
Select() 102
SelectAll() 101
SelectedDate 110
SelectedDatesChanged 110
SelectedIndex 108, 115
SelectedItem 240
SelectedText 99
SelectionChanged 102, 109, 116
SelectionLength 100
SelectionStart 100
SetEntitySetAccessRule 392
SetLink() 407
SetSource() 367
ShadowDepth 298
Show() 336, 341
ShowDialog() 360
ShowGridLines 85
Sign() 180

443

SilverlightHost 416
Sin() 180
Size 281
SkewTransform 302
SkipToFill() 319
Slider 111
SmallChange 111
SolidColorBrush 286
Source 121, 122, 124, 126, 228, 323
SourceName 293
SpeedRatio 318
SplineColorKeyFrame 314
SplineDoubleKeyFrame 314
SplinePointKeyFrame 314
SpreadMethod 289
SQL 250
Sqrt() 180
Stack 210
StackOverflowException 215
StackPanel 89
StartPoint 276, 279, 287
Static 182, 183
Stop() 126, 319
StopLoading() 328
Storyboard 308
Storyboard.TargetName 310
Storyboard.TargetProperty 310
Stream 348
StreamReader 350
StreamWriter 349
Stretch 121, 292
String 178
Stroke 271
StrokeThickness 271
Struct 196, 197
Substring() 179
Sum() 261
SweepDirection 281
Switch 157
SystemException 215

T
TabControl 114
TabIndex 101
TabItem 115
TabStripPlacement 115
Tan() 180

444

TargetName 331
Text 93, 99, 111
TextAlignment 94
TextBlock 93
TextBox 99
TextChanged 102
TextDecorationCollection 94
TextDecorations 94
TextWrapping 94
Thickness 284
This 174
Throw 219
Timeline 308
TimelineCollection 308
TimeOfDay 194
TimeSpan 195
Title 325, 335
To 309
Today 194
ToLower() 179
ToolTip 414
ToolTipService.ToolTip 414
ToString() 191
TotalDays 195
TotalHours 195
TotalMilliseconds 195
TotalMinutes 195
TotalSeconds 195
ToUpper() 179
Transform 299
TransformCollection 303
TransformGroup 303
TranslateTransform 300
Try 217
TryGetValue() 208
TryParse() 191
Type 234

U
UIElement 212
UIElementCollection 212
Unchecked 106
Unicode 141
UpdateObject() 405
Uri 123
UriKind 123

UserControl 47, 91
UserState 368

V
ValidatesOnExceptions 232
Value 111, 112, 209, 259, 314
ValueChanged 112
Var 254
VerticalAlignment 84
VerticalOffset 415
VerticalScrollBarVisibility 100, 114, 242
VideoBrush 293
Virtual 184
Visibility 85
Void 184
Volume 125

W
WebClient 365
Web- 9
Web-
16
13
Web- 10
Web- 11
Web- 375
395
Web- 9
12
Web- 12
Web- 14
Where 255
While 160, 161
Width 83, 87
World Wide Web 9
WriteLine() 350

X
X 300
X:Class 47
X:Key 227
X:Name 57
X1 271
X2 271

XAML 33, 44
XML 33
Xmlns 79

445

Y2 271
Year 194

Z
Z- 90

Y 300
Y1 271

49
261

307
306
306
45, 46, 58

376
376
377
162
16, 73, 74
155

421
422
422
422
293
12
60, 137
155
157
155
64, 155

9
286, 289
258
307
303
277
258

149
435

Add Connection 379
Add Existing Item 129
Add New Item 324
Add Reference 74
Add Service Reference 394
Assembly Information 427
Change Data Source 379
Choose Name 383
Configuration Manager 423
Entity Data Model Wizard 388
Foreign Key Relationships 384
Install application 432
New Project 40
New Silverlight Application 41, 393
Open File 67
Open Project 66

446

(.)
Out-of-Browser Settings 430
Tables And Columns 385

52
352
377
250
263
52

346
31, 57, 76, 146
77, 78
77
163
253
149
- 10
22, 196
214
18
325
10
47

307
354
30, 168
182
181
32
201
32
181
32
182
181
207
258
57, 139

141
53, 200, 258
166
18
25
26
234
138
189
189
189
171
189
190
57, 169, 186, 187
26
"" 83
26
26
422
282
283
395

23

296
163, 173
164
163
163
162
30, 169
get 169
set 169
184
184
184
31
184
184
397
185

184
184
62
171
184
32
184
388
181

322
32

29, 168
53, 86

42
332
332
42
66
43
340
138
61, 138
149
162
150
185
219
166
61, 150
152
61, 150
161
176
145
158, 161
61
150
150
176

447

172
151
149
153
346
210
65

36, 113
Database Explorer 378
Error List 65
Output 65
Properties 130
Solution Explorer 43, 74
Toolbox 48
37
38
37
, 11
31, 169, 328
60, 137
263, 264
251
60, 147
252
172
84, 85, 199
84, 199
16
262
322
325
322
169, 377
183
183
183
377
383
183
171
377
183
274

448

416
333, 348
299
80
224, 413
22
13
153
306
39
66
66
40
398
75
75
78
79
79
276

228
31, 169
129
130
130
227
227
227, 308
40, 41, 387

10
73
73
30, 169
188
188
188
203
188
94, 171
32
188

258, 265, 266


279

141
141
207
28, 30, 170
29, 58, 92, 171
171
32
16
210
23
24
38
147
140
95, 190
159

377, 380, 384,

HTML 10
XAML 45
47
45
45
45
307
60, 139
253
171
144
143
254
173
62
64, 144
145
143
173
140
142
142

301
288
282

173
155


72

72
66
73
39, 43, 72
73
44, 66
73
40, 66, 71
72
66
255
31
322

- 366
418

449

286
286
289
291
285
285
158
161
161
165, 204, 209
160
161
158
159

239
247
239

14
295

12
17
18
33

Вам также может понравиться