从在该窗口的框架内调用的页面更新进度条(位于窗口中)

时间:2015-08-14 11:25:03

标签: c# wpf

正如问题所述,我在这里有一个进度条

<ProgressBar x:Name="progress_bar" HorizontalAlignment="Left" Height="3" Margin="148,75,0,0" VerticalAlignment="Top" Width="868" Foreground="#FF3B79D3" Background="Transparent" BorderBrush="#FF9DB0D8" x:FieldModifier="public" Grid.ColumnSpan="2" />

和Code Behind with Some尝试允许更新进度条。

  • 这里我将进度条设置为公共
  • 尝试了一个属性获取者Setter
  • 试过代表

    namespace dcn
    {
        /// Interaction logic for dash.xaml
        public partial class dash : Window
        {
            public static ProgressBar pr;
            public dash()
            {
                InitializeComponent();
                fwinitializing();
                progress_bar.Visibility = Visibility.Visible;
                pr = progress_bar;
            }
            private void UpdateProgressBar(int i)
            {
                Action action = () => { SetProgress(i); };
                progress_bar.Dispatcher.BeginInvoke(action);
            }
            public int prgbar
            {
                get { return (Int32)progress_bar.Value; }
                set
                {
                    //Console.WriteLine(value);
                    pr.Value = Convert.ToInt32(value);
                    progress_bar.Value = Convert.ToInt32(value);
                    tmp.Content = "Processing......" + value + "%";
                    UpdateProgressBar(Convert.ToInt32(value));
                }
            }
            private void SetProgress(int i)
            {
                progress_bar.Value = i;
            }
        }
    }
    

    现在在我的页面上,在上面窗口的框架内调用。在这里,我使用可正常工作的后台工作程序对MDB文件运行多个插入查询,如果放在此页面中,还会更新进度条。但我想更新Above Window的进度条。

    namespace dcn
    {
        /// <summary>
        /// Interaction logic for mach_sync.xaml
        /// </summary>
        public partial class mach_sync : Page
        {
            CABLE.Cable_app sending = new CABLE.Cable_app();
            string path = Environment.CurrentDirectory + "\\xyz.mdb";
            //string pass = "";
            string[] data = new string[10];
            BackgroundWorker cust_to_mdb;
            public mach_sync()
            {
                InitializeComponent();
                cust_to_mdb = new BackgroundWorker();
                // Some Background Worker Code
            }
            void cust_to_mdb_ProgressChanged(object sender, ProgressChangedEventArgs e)
            {
                dash da = new dash();
                da.prgbar = e.ProgressPercentage;
                da.progress_bar.Value = Convert.ToInt32(e.ProgressPercentage);
                da.tmp.Content = "Processing......" + da.prgbar.ToString() + "%";
                da.UpdateLayout();
                //progressBar1.Value = e.ProgressPercentage;
                //Console.WriteLine("Processing......" + da.prgbar.ToString() + "%");
            }
        }
    }
    

    任何建议都很棒。我已经使用此应用程序启动了c#。我是一名全职Web开发人员。

  • 0 个答案:

    没有答案