@@ -32,8 +32,7 @@ private static void OnEditorChanged(DependencyObject obj, DependencyPropertyChan
32
32
return ;
33
33
}
34
34
35
- var bar = obj as TextToolbar ;
36
- if ( bar != null )
35
+ if ( obj is TextToolbar bar )
37
36
{
38
37
var oldEditor = args . OldValue as RichEditBox ;
39
38
var newEditor = args . NewValue as RichEditBox ;
@@ -46,8 +45,15 @@ private static void OnEditorChanged(DependencyObject obj, DependencyPropertyChan
46
45
if ( newEditor != null )
47
46
{
48
47
newEditor . AddHandler ( KeyDownEvent , bar . KeyEventHandler , handledEventsToo : true ) ;
49
- bar . Formatter . SetModel ( bar ) ;
50
- bar . DefaultButtons = bar . Formatter . DefaultButtons ;
48
+ if ( bar . Formatter != null )
49
+ {
50
+ bar . Formatter . SetModel ( bar ) ;
51
+ bar . DefaultButtons = bar . Formatter . DefaultButtons ;
52
+ }
53
+ else
54
+ {
55
+ bar . DefaultButtons = null ;
56
+ }
51
57
}
52
58
53
59
var editorArgs = new EditorChangedArgs
@@ -67,16 +73,19 @@ private static void OnEditorChanged(DependencyObject obj, DependencyPropertyChan
67
73
/// <param name="args">Property Changed Args</param>
68
74
private static void OnFormatterChanged ( DependencyObject obj , DependencyPropertyChangedEventArgs args )
69
75
{
70
- if ( obj is TextToolbar bar && bar . Formatter != null )
76
+ if ( obj is TextToolbar bar )
71
77
{
72
78
if ( args . OldValue is Formatter formatter )
73
79
{
74
80
formatter . UnsetModel ( bar ) ;
75
81
}
76
82
77
- bar . Formatter . SetModel ( bar ) ;
78
- bar . DefaultButtons = bar . Formatter . DefaultButtons ;
79
- bar . BuildBar ( ) ;
83
+ if ( bar . Formatter != null )
84
+ {
85
+ bar . Formatter . SetModel ( bar ) ;
86
+ bar . DefaultButtons = bar . Formatter . DefaultButtons ;
87
+ bar . BuildBar ( ) ;
88
+ }
80
89
}
81
90
}
82
91
@@ -87,14 +96,11 @@ private static void OnFormatterChanged(DependencyObject obj, DependencyPropertyC
87
96
/// <param name="args">Property Changed Args</param>
88
97
private static void OnButtonMapChanged ( DependencyObject obj , DependencyPropertyChangedEventArgs args )
89
98
{
90
- var bar = obj as TextToolbar ;
91
- if ( bar != null )
99
+ if ( obj is TextToolbar bar )
92
100
{
93
- var oldSource = args . OldValue as ButtonMap ;
94
- var newSource = args . NewValue as ButtonMap ;
95
101
var root = bar . GetTemplateChild ( RootControl ) as CommandBar ;
96
102
97
- if ( oldSource != null )
103
+ if ( args . OldValue is ButtonMap oldSource )
98
104
{
99
105
oldSource . CollectionChanged -= bar . OnButtonMapModified ;
100
106
@@ -107,7 +113,7 @@ private static void OnButtonMapChanged(DependencyObject obj, DependencyPropertyC
107
113
}
108
114
}
109
115
110
- if ( newSource != null )
116
+ if ( args . NewValue is ButtonMap newSource )
111
117
{
112
118
newSource . CollectionChanged += bar . OnButtonMapModified ;
113
119
@@ -126,19 +132,16 @@ private static void OnButtonMapChanged(DependencyObject obj, DependencyPropertyC
126
132
/// <param name="args">Property Changed Args</param>
127
133
private static void OnDefaultButtonModificationsChanged ( DependencyObject obj , DependencyPropertyChangedEventArgs args )
128
134
{
129
- var bar = obj as TextToolbar ;
130
- if ( bar != null )
135
+ if ( obj is TextToolbar bar )
131
136
{
132
- var oldSource = args . OldValue as DefaultButtonModificationList ;
133
- var newSource = args . NewValue as DefaultButtonModificationList ;
134
137
var root = bar . GetTemplateChild ( RootControl ) as CommandBar ;
135
138
136
- if ( oldSource != null )
139
+ if ( args . OldValue is DefaultButtonModificationList oldSource )
137
140
{
138
141
oldSource . CollectionChanged -= bar . OnDefaultButtonModificationListChanged ;
139
142
}
140
143
141
- if ( newSource != null )
144
+ if ( args . NewValue is DefaultButtonModificationList newSource )
142
145
{
143
146
newSource . CollectionChanged += bar . OnDefaultButtonModificationListChanged ;
144
147
@@ -158,8 +161,7 @@ private static void OnDefaultButtonModificationsChanged(DependencyObject obj, De
158
161
/// <param name="e">Collection Changed Args</param>
159
162
private void OnButtonMapModified ( object sender , NotifyCollectionChangedEventArgs e )
160
163
{
161
- var root = GetTemplateChild ( RootControl ) as CommandBar ;
162
- if ( root != null )
164
+ if ( GetTemplateChild ( RootControl ) is CommandBar root )
163
165
{
164
166
switch ( e . Action )
165
167
{
@@ -168,8 +170,7 @@ private void OnButtonMapModified(object sender, NotifyCollectionChangedEventArgs
168
170
{
169
171
AddToolbarItem ( item , root ) ;
170
172
171
- var button = item as ToolbarButton ;
172
- if ( button != null )
173
+ if ( item is ToolbarButton button )
173
174
{
174
175
button . PropertyChanged += ToolbarItemPropertyChanged ;
175
176
}
@@ -182,8 +183,7 @@ private void OnButtonMapModified(object sender, NotifyCollectionChangedEventArgs
182
183
{
183
184
RemoveToolbarItem ( item ) ;
184
185
185
- var button = item as ToolbarButton ;
186
- if ( button != null )
186
+ if ( item is ToolbarButton button )
187
187
{
188
188
button . PropertyChanged -= ToolbarItemPropertyChanged ;
189
189
}
@@ -225,8 +225,7 @@ private void OnDefaultButtonModificationListChanged(object sender, NotifyCollect
225
225
/// <param name="e">Property Changed Event</param>
226
226
private void ToolbarItemPropertyChanged ( object sender , System . ComponentModel . PropertyChangedEventArgs e )
227
227
{
228
- var root = GetTemplateChild ( RootControl ) as CommandBar ;
229
- if ( root != null )
228
+ if ( GetTemplateChild ( RootControl ) is CommandBar root )
230
229
{
231
230
if ( e . PropertyName == nameof ( IToolbarItem . Position ) )
232
231
{
@@ -249,8 +248,7 @@ private void Editor_KeyDown(object sender, KeyRoutedEventArgs e)
249
248
250
249
LastKeyPress = e . Key ;
251
250
252
- var root = GetTemplateChild ( RootControl ) as CommandBar ;
253
- if ( root != null )
251
+ if ( GetTemplateChild ( RootControl ) is CommandBar root )
254
252
{
255
253
if ( ControlKeyDown && e . Key != VirtualKey . Control )
256
254
{
0 commit comments