/
window1.xaml.cs
513 lines (475 loc) · 17.4 KB
/
window1.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
using System;
using System.Windows;
using System.Collections;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Documents;
namespace SDKSample
{
public partial class Window1 : Window
{
public void makebgVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp1.Children)
{
child.Visibility = Visibility.Collapsed;
}
backgroundProp.Visibility = Visibility.Visible;
tb2.Text = "If you set the Foreground and Background colors to the same color, TextContent will no longer be visible.";
}
public void makeboVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp1.Children)
{
child.Visibility = Visibility.Collapsed;
}
baselineOffsetProp.Visibility = Visibility.Visible;
tb2.Text = "";
tb3.Visibility = Visibility.Visible;
tb3.FontWeight = FontWeights.Bold;
tb3.Text = "Another TextBlock Element.";
}
public void makebaVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp1.Children)
{
child.Visibility = Visibility.Collapsed;
}
breakafterProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void makebbVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp1.Children)
{
child.Visibility = Visibility.Collapsed;
}
breakbeforeProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void makeffVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp1.Children)
{
child.Visibility = Visibility.Collapsed;
}
fontfamilyProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void makefsVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp1.Children)
{
child.Visibility = Visibility.Collapsed;
}
fontsizeProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void makefstVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp1.Children)
{
child.Visibility = Visibility.Collapsed;
}
fontstretchProp.Visibility = Visibility.Visible;
tb2.Text = "Some fonts do not support all FontStretch values.";
}
public void makefstyleVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp1.Children)
{
child.Visibility = Visibility.Collapsed;
}
fontstyleProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void makefwVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
fontweightProp.Visibility = Visibility.Visible;
tb2.Text = "Not all FontWeight values result in unique rendering.";
}
public void makefgVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
foregroundProp.Visibility = Visibility.Visible;
tb2.Text = "If you set the Foreground and Background colors to the same color, TextContent will no longer be visible.";
}
public void makelhVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
lineheightProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void maketaVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
textalignmentProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void maketdVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
textdecorationsProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void maketcVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
textcontentProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void makettVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
texttrimmingProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void maketeVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
texteffectsProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
public void maketwVisible(object sender, RoutedEventArgs e)
{
foreach (UIElement child in sp2.Children)
{
child.Visibility = Visibility.Collapsed;
}
textwrapProp.Visibility = Visibility.Visible;
tb2.Text = "";
}
// Begin Background change methods
public void setBackgroundRed(object sender, RoutedEventArgs e)
{
tb1.Background = Brushes.Red;
}
public void setBackgroundBlue(object sender, RoutedEventArgs e)
{
tb1.Background = Brushes.Blue;
}
public void setBackgroundGreen(object sender, RoutedEventArgs e)
{
tb1.Background = Brushes.Green;
}
public void setBackgroundPurple(object sender, RoutedEventArgs e)
{
tb1.Background = Brushes.Purple;
}
public void setBackgroundWhite(object sender, RoutedEventArgs e)
{
tb1.Background = Brushes.White;
}
// Begin BaselineOffset change methods
public void offsetChange10(object sender, RoutedEventArgs e)
{
tb3.BaselineOffset = 10;
}
public void offsetChange20(object sender, RoutedEventArgs e)
{
tb3.BaselineOffset = 20;
}
public void offsetChange30(object sender, RoutedEventArgs e)
{
tb3.BaselineOffset = 30;
}
public void offsetChange40(object sender, RoutedEventArgs e)
{
tb3.BaselineOffset = 40;
}
// Begin BreakAfter change methods
public void getbaValue(object sender, RoutedEventArgs e)
{
tb2.Text = "BreakAfter value is set to " + tb1.BreakAfter.ToString();
}
// Begin BreakBefore change methods
public void getbbValue(object sender, RoutedEventArgs e)
{
tb2.Text = "BreakBefore value is set to " + tb1.BreakBefore.ToString();
}
// Begin FontFamily change methods
public void ffTimes(object sender, RoutedEventArgs e)
{
tb1.FontFamily = new FontFamily("Times New Roman");
}
public void ffVerdana(object sender, RoutedEventArgs e)
{
tb1.FontFamily = new FontFamily("Verdana");
}
public void ffPalatino(object sender, RoutedEventArgs e)
{
tb1.FontFamily = new FontFamily("Palatino Linotype");
}
public void ffCourier(object sender, RoutedEventArgs e)
{
tb1.FontFamily = new FontFamily("Courier New");
}
// Begin FontSize change methods
public void fs10(object sender, RoutedEventArgs e)
{
tb1.FontSize = 10;
}
public void fs15(object sender, RoutedEventArgs e)
{
tb1.FontSize = 15;
}
public void fs20(object sender, RoutedEventArgs e)
{
tb1.FontSize = 20;
}
public void fs25(object sender, RoutedEventArgs e)
{
tb1.FontSize = 25;
}
// Begin FontStretch change methods
public void fstNormal(object sender, RoutedEventArgs e)
{
tb1.FontStretch = FontStretches.Normal;
}
public void fstCondensed(object sender, RoutedEventArgs e)
{
tb1.FontStretch = FontStretches.Condensed;
}
public void fstExpanded(object sender, RoutedEventArgs e)
{
tb1.FontStretch = FontStretches.Expanded;
}
public void fstMedium(object sender, RoutedEventArgs e)
{
tb1.FontStretch = FontStretches.Medium;
}
// Begin FontWeight change methods
public void fwNormal(object sender, RoutedEventArgs e)
{
tb1.FontWeight = FontWeights.Normal;
}
public void fwLight(object sender, RoutedEventArgs e)
{
tb1.FontWeight = FontWeights.Light;
}
public void fwMedium(object sender, RoutedEventArgs e)
{
tb1.FontWeight = FontWeights.Medium;
}
public void fwBold(object sender, RoutedEventArgs e)
{
tb1.FontWeight = FontWeights.Bold;
}
public void fwUltraBold(object sender, RoutedEventArgs e)
{
tb1.FontWeight = FontWeights.UltraBold;
}
// Begin FontStyle change methods
public void fstyleNormal(object sender, RoutedEventArgs e)
{
tb1.FontStyle = FontStyles.Normal;
}
public void fstyleItalic(object sender, RoutedEventArgs e)
{
tb1.FontStyle = FontStyles.Italic;
}
public void fstyleOblique(object sender, RoutedEventArgs e)
{
tb1.FontStyle = FontStyles.Oblique;
}
// Begin Foreground change methods
public void foregroundWhite(object sender, RoutedEventArgs e)
{
tb1.Foreground = Brushes.White;
}
public void foregroundBlack(object sender, RoutedEventArgs e)
{
tb1.Foreground = Brushes.Black;
}
public void foregroundBlue(object sender, RoutedEventArgs e)
{
tb1.Foreground = Brushes.Blue ;
}
public void foregroundRed(object sender, RoutedEventArgs e)
{
tb1.Foreground = Brushes.Red;
}
// Begin Lineheight change methods
public void lineheight10(object sender, RoutedEventArgs e)
{
tb1.LineHeight = 10;
}
public void lineheight20(object sender, RoutedEventArgs e)
{
tb1.LineHeight = 20;
}
public void lineheight30(object sender, RoutedEventArgs e)
{
tb1.LineHeight = 30;
}
public void lineheight40(object sender, RoutedEventArgs e)
{
tb1.LineHeight = 40;
}
// Begin TextAlignment change methods
public void talignLeft(object sender, RoutedEventArgs e)
{
tb1.TextAlignment = TextAlignment.Left;
}
public void talignRight(object sender, RoutedEventArgs e)
{
tb1.TextAlignment = TextAlignment.Right;
}
public void talignCenter(object sender, RoutedEventArgs e)
{
tb1.TextAlignment = TextAlignment.Center;
}
public void talignJustify(object sender, RoutedEventArgs e)
{
tb1.TextAlignment = TextAlignment.Justify;
}
// Begin TextContent change methods
public void tcUpdate(object sender, RoutedEventArgs e)
{
tb1.Text = tbox1.SelectedText;
}
// Begin TextWrap change methods
public void wrapWrap(object sender, RoutedEventArgs e)
{
tb1.TextWrapping = TextWrapping.Wrap;
}
public void wrapNoWrap(object sender, RoutedEventArgs e)
{
tb1.TextWrapping = TextWrapping.NoWrap;
}
public void wrapWrapWithOverflow(object sender, RoutedEventArgs e)
{
tb1.TextWrapping = TextWrapping.WrapWithOverflow;
}
// Begin TextTrimming change methods
public void trimNone(object sender, RoutedEventArgs e)
{
tb1.TextTrimming = TextTrimming.None;
}
public void trimWord(object sender, RoutedEventArgs e)
{
tb1.TextTrimming = TextTrimming.WordEllipsis;
}
public void trimCharacter(object sender, RoutedEventArgs e)
{
tb1.TextTrimming = TextTrimming.CharacterEllipsis;
}
// Begin TextDecorations change methods
public void tdBase(object sender, RoutedEventArgs e)
{
TextDecorationCollection myCollection = new TextDecorationCollection();
TextDecoration myBaseline = new TextDecoration();
myBaseline.Location = TextDecorationLocation.Baseline;
myBaseline.Pen = new Pen(Brushes.Red, 1);
myBaseline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
myCollection.Add(myBaseline);
tb1.TextDecorations = myCollection;
}
public void tdUnder(object sender, RoutedEventArgs e)
{
TextDecorationCollection myCollection = new TextDecorationCollection();
TextDecoration myUnderline = new TextDecoration();
myUnderline.Location = TextDecorationLocation.Underline;
myUnderline.Pen = new Pen(Brushes.Red, 1);
myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
myCollection.Add(myUnderline);
tb1.TextDecorations = myCollection;
}
public void tdStrike(object sender, RoutedEventArgs e)
{
TextDecorationCollection myCollection = new TextDecorationCollection();
TextDecoration myStrikethrough = new TextDecoration();
myStrikethrough.Location = TextDecorationLocation.Strikethrough;
myStrikethrough.Pen = new Pen(Brushes.Red, 1);
myStrikethrough.PenThicknessUnit = TextDecorationUnit.FontRecommended;
myCollection.Add(myStrikethrough);
tb1.TextDecorations = myCollection;
}
public void tdOver(object sender, RoutedEventArgs e)
{
TextDecorationCollection myCollection = new TextDecorationCollection();
TextDecoration myOverline = new TextDecoration();
myOverline.Location = TextDecorationLocation.OverLine;
myOverline.Pen = new Pen(Brushes.Red, 1);
myOverline.PenThicknessUnit = TextDecorationUnit.FontRecommended;
myCollection.Add(myOverline);
tb1.TextDecorations = myCollection;
}
// Begin TextEffect methods
public void teTranslate(object sender, RoutedEventArgs e)
{
DisableTextEffects();
TextEffect myEffect = new TextEffect();
myEffect.PositionStart = 0;
myEffect.PositionCount = 999;
TranslateTransform myTranslateTransform = new TranslateTransform(50,50);
myEffect.Transform = myTranslateTransform;
EnableTextEffects(tb1, myEffect);
tb2.Text = "The TranslateTransform applied moved the TextBlock to an offset position of 50,50.";
}
public void teScale(object sender, RoutedEventArgs e)
{
DisableTextEffects();
TextEffect myEffect = new TextEffect();
myEffect.PositionStart = 0;
myEffect.PositionCount = 999;
ScaleTransform myScaleTransform = new ScaleTransform(5,5);
myEffect.Transform = myScaleTransform;
EnableTextEffects(tb1, myEffect);
tb2.Text = "The ScaleTransform applied scaled the text by a factor of 5.";
}
public void teRotate(object sender, RoutedEventArgs e)
{
DisableTextEffects();
TextEffect myEffect = new TextEffect();
myEffect.PositionStart = 0;
myEffect.PositionCount = 999;
RotateTransform myRotateTransform = new RotateTransform(45);
myEffect.Transform = myRotateTransform;
EnableTextEffects(tb1, myEffect);
tb2.Text = "The RotateTransform applied rotated the text by 45 degrees.";
}
private void DisableTextEffects()
{
if (_textEffectTargets != null)
{
foreach (TextEffectTarget target in _textEffectTargets)
target.Disable();
}
}
private void EnableTextEffects(TextBlock tb, TextEffect effect)
{
_textEffectTargets = TextEffectResolver.Resolve(tb.ContentStart, tb.ContentEnd, effect);
foreach (TextEffectTarget target in _textEffectTargets)
target.Enable();
}
private TextEffectTarget[] _textEffectTargets;
private int Gareth2;
}
}