66using System . Linq ;
77using System . Text ;
88using System . Threading . Tasks ;
9+ using System . Windows ;
910using System . Windows . Media ;
1011
1112namespace CutCode
@@ -23,13 +24,12 @@ public HomeViewModel(IThemeService _themeService, IPageService _pageService, IDa
2324 pageService = _pageService ;
2425
2526 database = _dataBase ;
27+ AllCodes = database . AllCodes ;
2628 database . AllCodesUpdated += AllCodesUpdated ;
2729
2830 SetAppearance ( ) ;
2931 IsSearched = false ;
3032
31- AllCodes = database . AllCodes ;
32-
3333 AllLangs = new ObservableCollection < string > ( )
3434 {
3535 "All languages" , "Python" , "C++" , "C#" , "CSS" , "Dart" , "Golang" , "Html" , "Java" ,
@@ -41,8 +41,6 @@ private void ThemeChanged(object sender, EventArgs e)
4141 {
4242 SetAppearance ( ) ;
4343 }
44- private void AllCodesUpdated ( object sender , EventArgs e ) => AllCodes = database . AllCodes ;
45-
4644 private void SetAppearance ( )
4745 {
4846 Theme = themeService . IsLightTheme ;
@@ -52,6 +50,7 @@ private void SetAppearance()
5250 comboboxHoverColor = themeService . IsLightTheme ? ColorCon . Convert ( "#C5C7C9" ) : ColorCon . Convert ( "#202326" ) ;
5351 comboboxBackgroundColor = themeService . IsLightTheme ? ColorCon . Convert ( "#E3E5E8" ) : ColorCon . Convert ( "#202225" ) ;
5452 }
53+ private void AllCodesUpdated ( object sender , EventArgs e ) => AllCodes = database . AllCodes ;
5554
5655 public ObservableCollection < CodeBoxModel > AllCodes { get ; set ; }
5756 public IList < string > AllLangs { get ; set ; }
@@ -121,7 +120,7 @@ public string CurrentSort1
121120 set
122121 {
123122 SetAndNotify ( ref _CurrentSort1 , value ) ;
124- ComboBoxItemSelected ( value ) ;
123+ Application . Current . Dispatcher . Invoke ( new Action ( ( ) => { ComboBoxItemSelected ( value ) ; } ) ) ;
125124 }
126125 }
127126
@@ -132,7 +131,7 @@ public string CurrentSort2
132131 set
133132 {
134133 SetAndNotify ( ref _CurrentSort2 , value ) ;
135- ComboBoxItemSelected ( value ) ;
134+ Application . Current . Dispatcher . Invoke ( new Action ( ( ) => { ComboBoxItemSelected ( value ) ; } ) ) ;
136135 }
137136 }
138137
0 commit comments