33
44using System ;
55using System . Collections . Generic ;
6+ using System . Collections . Specialized ;
67using System . Linq ;
78using System . Text ;
89using System . ComponentModel ;
910using System . Collections . ObjectModel ;
1011using System . Threading ;
1112using System . Globalization ;
13+ using System . Windows . Controls ;
14+ using System . Windows . Controls . Primitives ;
1215using ICSharpCode . WpfDesign . PropertyGrid ;
1316using System . Windows . Threading ;
1417using System . Diagnostics ;
@@ -31,7 +34,7 @@ public PropertyGrid()
3134 }
3235
3336 Category specialCategory = new Category ( "Special" ) ;
34- Category popularCategory = new Category ( "Popular" ) ;
37+ Category popularCategory = new Category ( "Popular" ) ;
3538 Category otherCategory = new Category ( "Other" ) ;
3639 Category attachedCategory = new Category ( "Attached" ) ;
3740
@@ -158,14 +161,17 @@ public bool IsNameEnabled {
158161 }
159162 }
160163
161- IEnumerable < DesignItem > selectedItems ;
164+ IList < DesignItem > selectedItems ;
162165
163166 public IEnumerable < DesignItem > SelectedItems {
164167 get {
165168 return selectedItems ;
166169 }
167170 set {
168- selectedItems = value ;
171+ if ( value == null )
172+ selectedItems = null ;
173+ else
174+ selectedItems = value . ToList ( ) ;
169175 RaisePropertyChanged ( "SelectedItems" ) ;
170176 Dispatcher . CurrentDispatcher . BeginInvoke ( DispatcherPriority . Background , new Action (
171177 delegate {
@@ -178,17 +184,27 @@ public void ClearFilter()
178184 {
179185 Filter = null ;
180186 }
187+
188+ volatile bool reloadActive ;
189+ public bool ReloadActive {
190+ get { return reloadActive ; }
191+ }
181192
182193 void Reload ( )
183194 {
184- Clear ( ) ;
185-
186- if ( SelectedItems == null || SelectedItems . Count ( ) == 0 ) return ;
187- if ( SelectedItems . Count ( ) == 1 ) SingleItem = SelectedItems . First ( ) ;
188-
189- foreach ( var md in GetDescriptors ( ) ) {
190- if ( PassesFilter ( md . Name ) )
191- AddNode ( md ) ;
195+ reloadActive = true ;
196+ try {
197+ Clear ( ) ;
198+
199+ if ( selectedItems == null || selectedItems . Count == 0 ) return ;
200+ if ( selectedItems . Count == 1 ) SingleItem = selectedItems [ 0 ] ;
201+
202+ foreach ( var md in GetDescriptors ( ) ) {
203+ if ( PassesFilter ( md . Name ) )
204+ AddNode ( md ) ;
205+ }
206+ } finally {
207+ reloadActive = false ;
192208 }
193209 }
194210
@@ -233,7 +249,7 @@ bool PassesFilter(string name)
233249 if ( string . IsNullOrEmpty ( Filter ) ) return true ;
234250 for ( int i = 0 ; i < name . Length ; i ++ ) {
235251 if ( i == 0 || char . IsUpper ( name [ i ] ) ) {
236- if ( string . Compare ( name , i , Filter , 0 , Filter . Length , true ) == 0 ) {
252+ if ( string . Compare ( name , i , Filter , 0 , Filter . Length , StringComparison . OrdinalIgnoreCase ) == 0 ) {
237253 return true ;
238254 }
239255 }
@@ -271,7 +287,7 @@ Category PickCategory(PropertyNode node)
271287 if ( Metadata . IsPopularProperty ( node . FirstProperty ) ) return popularCategory ;
272288 if ( node . FirstProperty . IsAttachedDependencyProperty ( ) ) return attachedCategory ;
273289 var typeName = node . FirstProperty . DeclaringType . FullName ;
274- if ( typeName . StartsWith ( "System.Windows." ) || typeName . StartsWith ( "ICSharpCode.WpfDesign.Designer.Controls." ) )
290+ if ( typeName . StartsWith ( "System.Windows." , StringComparison . Ordinal ) || typeName . StartsWith ( "ICSharpCode.WpfDesign.Designer.Controls." , StringComparison . Ordinal ) )
275291 return otherCategory ;
276292 return specialCategory ;
277293 }
0 commit comments