Tuesday, 15 January 2013

c# - WPF Update grid visibility -


After a few searches on the web I have set this simple example:

PropertyChangedBase.cs

  Changing property of public class Buzz: INotifyPropertyChanged {Private Event PropertyChangedEventHandler PropertyChanged; Protected Virtual Zero OnPropertyChanged (string property) {// Raise PropertyChanged Event on UI Thread with relevant property parameters: Application.Current.Dispatcher.BeginInvoke ((Action) ((=) => {PropertyChangedEventHandler Handler = PropertyChanged, if ( Handler! = Null) handler (this, new property change and name (property name));})); }}  

UserViewModel.cs

  public class UserViewModel: PropertyChangedBase {Private Visibility _showUserWindow = Visibility.Collapsed; Public Visualization ShowSure Window {Get {return _showUserWindow; } Set {_showUserWindow = value; OnPropertyChanged ("ShowUserWindow"); //this is important!!! }}}  

MainWindow.xaml

  & lt; Window X: Class = "WpfApplication1.MainWindow" xmlns = "http://schemas.microsoft.com/comfx/ 2006/XAML/Presentation" xmlns: x = "http://schemas.microsoft.com/winfx/2006/ Xaml "title =" MainWindow "height =" 350 "width =" 525 "& gt; & Lt; Grid & gt; & Lt; Grid margin = "43,28,247,129" background = "alisblue" visibility = "{bining showsure window}" /> & Lt; Button content = "button" HorizontalAlignment = "left" margin = "349,150,0,0" VerticalAlignment = "top" width = "75" PreviewMouseLeftButtonDown = "Button_PreviewMouseLeftButtonDown" /> & Lt; / Grid & gt; & Lt; / Window & gt;  

MainWindow.xaml.cs

  Public partial square main window: Window {UserViewModel userViewModel; Public Manvindo () {Initialization (); UserViewModel = New UserViewModel (); DataContext = userViewModel; } Private Zero Button_PreviewMouseLeftButtonDown (Object Sender, MouseButtonEventArgs e) {userViewModel.ShowUserWindow = Visibility.Visible; Thread.Sleep (1000); UserViewModel.ShowUserWindow = Visibility Collapsed; }}  

Now the grid falls after 1 second, before the timer starts I would like to update the UI. What am i doing wrong

Edit: Thread The sleep line unchanges some work, which takes some time to complete. Before the work begins, the grid should be visible and show some information about that work and the work will be collapsed after completion.

OK, you have threads on a thread. Sleep (1000) should be considered for operation, not on the UI thread. Also, try setting the yourGrid.UpdateLayout () method after setting the visas to collapsed .

LE: Most probably, its threads. Sleep (1000) stands for something like a database operation, for example, takes some time.

Check LE2: A BackgroundWorker will do the trick!


No comments:

Post a Comment