/
ColorFontDialog.xaml.cs
114 lines (100 loc) · 2.98 KB
/
ColorFontDialog.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
using System.Text;
using System.Windows;
using System.Windows.Media;
using ToDoLib;
namespace ColorFont
{
/// <summary>
/// Interaction logic for ColorFontDialog.xaml
/// </summary>
public partial class ColorFontDialog : Window
{
private FontInfo selectedFont;
public ColorFontDialog()
{
Log.Debug("Loading ColorFontDialog");
this.selectedFont = null; // Default
InitializeComponent();
}
public FontInfo Font
{
get
{
return this.selectedFont;
}
set
{
FontInfo fi = value;
this.selectedFont = fi;
}
}
private void SyncFontName()
{
Log.Debug("In SyncFontName");
string fontFamilyName = this.selectedFont.Family.Source;
bool isFontFound = false;
int idx = 0;
foreach (var item in this.colorFontChooser.lstFamily.Items)
{
string itemName = item.ToString();
if (fontFamilyName == itemName)
{
isFontFound = true;
break;
}
idx++;
}
if (!isFontFound)
{
idx = 0;
}
this.colorFontChooser.lstFamily.SelectedIndex = idx;
this.colorFontChooser.lstFamily.ScrollIntoView(this.colorFontChooser.lstFamily.Items[idx]);
}
private void SyncFontSize()
{
Log.Debug("In SyncFontSize");
double fontSize = this.selectedFont.Size;
this.colorFontChooser.fontSizeSlider.Value = fontSize;
}
private void SyncFontColor()
{
Log.Debug("In SyncFontColor");
int colorIdx = AvailableColors.GetFontColorIndex(this.Font.Color);
this.colorFontChooser.colorPicker.superCombo.SelectedIndex = colorIdx;
// The following does not work. Why???
// this.colorFontChooser.colorPicker.superCombo.SelectedValue = this.Font.Color;
this.colorFontChooser.colorPicker.superCombo.BringIntoView();
}
private void SyncFontTypeface()
{
Log.Debug("In SyncFontTypeface");
string fontTypeFaceSb = FontInfo.TypefaceToString(this.selectedFont.Typeface);
int idx = 0;
foreach (var item in this.colorFontChooser.lstTypefaces.Items)
{
FamilyTypeface face = item as FamilyTypeface;
if (fontTypeFaceSb == FontInfo.TypefaceToString(face))
{
break;
}
idx++;
}
this.colorFontChooser.lstTypefaces.SelectedIndex = idx;
}
private void btnOk_Click(object sender, RoutedEventArgs e)
{
this.Font = this.colorFontChooser.SelectedFont;
this.DialogResult = true;
}
private void Window_Loaded_1(object sender, RoutedEventArgs e)
{
Log.Debug("In Window_Loaded_1" );
this.SyncFontColor();
this.SyncFontName();
this.SyncFontSize();
this.SyncFontTypeface();
Log.Debug("Leaving Window_Loaded_1");
}
}
}