Wpf progressbar binding not updating dating during the renaissance
In the XAML for the Main Page you need to create an instance of the Main Page View Model in the Resources section of the page, which is then set as the Data Context for the page so that you can data bind to properties on it. Begin Invoke to ensure it is carried out on the UI thread.
Alternatively you could create this in code when the page is loaded and assign it to the Data Context property of the page. As you can see from the code, Main Page View Model implements the INotify Property Changed interface and raises the Property Changed event whenever either the Text Block Text or the Is Loading property changes.
Let's walk this through with a simple example, starting with a basic user interface that contains a start Button, a Progress Bar and a Text Block.
When the user clicks the start Button, the Progress Bar is displayed while the data is being loaded.
Visibility: Used to display and hide the Text Block This would result in the following Main Page View Model: As you can see this can lead to a lot of properties that need to be updated every time data is loaded.
Is Indeterminate: Rather than show an actual progress we'll just use the Indeterminate state to illustrate that data is being loaded [Progress Bar].We can then use data binding to connect the View with the View Model.The Main Page View Model class will be used to track the current state of the page.However, this often leads the user to query whether anything is happening; which leads to the use of a progress bar to indicate that some activity is being executed in the background.
Once the data has been loaded the progress bar should be hidden and the relevant controls to display the data should be shown.
Start Button Is Enabled will always be false, when data is being loaded, and vice versa; Progress Bar Visibility will always be Visible when data is being loaded, and Collapsed when it's not; Text Block Visibility will always be Collapsed when data is being loaded, and Visible when it's not.