Click here to Skip to main content
14,975,411 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All Experts,

I got some problem in showing download percentage in GridView of WCF.i used MVVM pattern. here is my background worker in application start.

public partial class MainWindow : Window
   {
       public MainWindow()
       {
           Overall.EverythingOk = "Nothing";

           InitializeComponent();
           //IRepo repo = new Repo();
           ViewModel.MainWindowsViewModel viewModel = new ViewModel.MainWindowsViewModel();
           this.DataContext = viewModel;

           BackGroundThread bgT = new BackGroundThread();
           bgT.bgWrk.RunWorkerAsync();
       }
   }


Here is the DoWork function in BackGroundTHread class

public void bw_DoWork(object sender, DoWorkEventArgs e)
       {
           if (!Overall.stopStatus)
           {
               for (int i=0; i < 10000; i++)
               {
                   Overall.PercentageDwnd = i;
                   Overall.caseRefId = "999999";
                   if (i == 9998)
                   {
                       i = 1;
                   }
               }
           }
       }


Overall.PercentageDwnd and Overall.caseRefId are static variable(you can call from everywhere in the application) and always update until the backgroundworker completed. I got another viewmodel called TestViewModel and here it is.

public class TestViewModel:BindableBase
    {        
        private String _UpdatePer=Overall.PercentageDwnd.ToString();
        public String UpdatePercentage
        {
            get { return _UpdatePer; }
            set { SetProperty(ref _UpdatePer, value); }
        }

        private ObservableCollection<tblTransaction> _ViewAKA = new ObservableCollection<tblTransaction>();
        private tblTransaction model;

        public TestViewModel(tblTransaction model)
        {
            // TODO: Complete member initialization
            
        }
        public ObservableCollection<tblTransaction> ViewAKA
        {
            get { return _ViewAKA; }
            set { SetProperty(ref _ViewAKA, value); }
        }
    }


I bind with TestView.xaml file

<Window x:Class="EmployeeManager.View.TestView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="TestView" Height="359.774" Width="542.481">
    <Grid Margin="0,0,2,0">
        <Label Content="{Binding UpdatePercentage,UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Background="Red" Foreground="White" Margin="130,86,0,0" VerticalAlignment="Top" Width="132" Height="39">
            
        </Label>

    </Grid>
</Window>


How can i realtime update Percentage in Label? quite newbie in WPF as well as MVVM

THanks
Weeiyourda
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900