01/10/2018, 01:09 
               
            Thanh ProgressBar trong WPF
Cho e hỏi 2 đoạn code sau khác nhau chỗ nào mà dòng trên chạy được dòng dưới thì ko vậy các bác
this.Dispatcher.Invoke(delegate
{
    pbMyProgressBar.Value = i;
});
và
{
    pbMyProgressBar.Value = (i/200)*100;
});`
Code đầy đủ
XAML:
`<Window x:Class="WpfApplication3.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid Margin="0,0,2,289">
        <ProgressBar x:Name="pbMyProgressBar" Maximum="100" Minimum="0"/>
        <Button Margin="186,102,145,-163" Click="Button_Click">
            MyButton
        </Button>
    </Grid>
</Window>
CS:
namespace WpfApplication3
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Thread th = new Thread(WorkMethod);
            th.Start();
        }
        private void WorkMethod()
        {
            int i = 0;
            while (i < 200)
            {
                Thread.Sleep(80);
                this.Dispatcher.Invoke(delegate
                {
                    pbMyProgressBar.Value = (i/200)*100;
                });
                i++;
            }
        }
    }
}
            
            Bài liên quan
         
               
            




Bởi vì i là integer. i/200 luôn <1 nên kết quả trả về luôn =0;
Hãy thử biểu thức thế này :
tks bác nhiều nha