WPF为什么我的ObservableCollection对象集合不更新我的ProgressBar

WPF为什么我的ObservableCollection对象集合不更新我的ProgressBar,wpf,listview,progress-bar,Wpf,Listview,Progress Bar,我有WPF应用程序,我正在使用PcapDotNet DLL通过网卡发送数据包 这是我的对象,表示Wireshark文件: public class WiresharkFile { public event PropertyChangedEventHandler PropertyChanged; virtual public void NotifyPropertyChange(string propertyName) { var handler = Pro

我有
WPF应用程序
,我正在使用
PcapDotNet DLL
通过
网卡
发送
数据包

这是我的对象,表示
Wireshark文件

public class WiresharkFile
{
    public event PropertyChangedEventHandler PropertyChanged;

    virtual public void NotifyPropertyChange(string propertyName)
    {
        var handler = PropertyChanged;
        if (handler != null)
            handler(this, new PropertyChangedEventArgs(propertyName));
    }

   private string _file; // file path
   private string _packets; // how many packet in file
   private string _sentPackets; // how many packet sent
   private string _progress; // percentage (_sentPackets/_packets) * 100

   public int Progress
   {
       get { return _progress; }
       set
       {
           _progress = value;
           NotifyPropertyChange("Progress");
       }
   }

   public void Transmit(WireshrkFile)
   {
         // here i am send the packets
   }
}
保存此对象的我的列表:

public ObservableCollection<WireshrkFile> files{ get; set; }
my
ListView中的进度条定义

<ListView.Resources>
    <DataTemplate x:Key="MyDataTemplate">
        <Grid Margin="-6">
            <ProgressBar Name="prog" Maximum="100" Value="{Binding Progress}" 
                         Width="{Binding Path=Width, ElementName=ProgressCell}" 
                         Height="20" Margin="0" Background="#FFD3D0D0" Style="{StaticResource CustomProgressBar}" />
            <TextBlock Text="{Binding Path=Value, ElementName=prog, StringFormat={}{0}%}" VerticalAlignment="Center"
                       HorizontalAlignment="Center" FontSize="11" Foreground="Black" />
        </Grid>
    </DataTemplate>
    <ControlTemplate x:Key="ProgressBarTemplate">
        <Label  HorizontalAlignment="Center" VerticalAlignment="Center" />
    </ControlTemplate>
</ListView.Resources>

正如您所看到的,它只能使指针指向相同的属性,但这是有效的。

我可以看到NotifyPropertyChange方法,但我没有看到INotifyPropertyChanged接口?!查看我的WiresharkFile类更新即使文件位于ObservableCollection内,WiresharkFile也需要实现INotifyPropertyChanged,以便其他类知道它们可以支持其更改。但除此之外。。。这可能是一个愚蠢的问题,但是,您是否使用异步调用?如果没有,您可能正在阻止UI线程,这将使ProgressBar在任务完成之前不会更新。要在我的类中实现INotifyPropertyChanged,需要做什么?顺便说一句,我通过任务打开了此传输仅此:
公共类WiresharkFile:INotifyPropertyChanged
我可以看到NotifyPropertyChange方法,但我看不到INotifyPropertyChanged接口?!查看我的WiresharkFile类更新即使文件位于ObservableCollection内,WiresharkFile也需要实现INotifyPropertyChanged,以便其他类知道它们可以支持其更改。但除此之外。。。这可能是一个愚蠢的问题,但是,您是否使用异步调用?如果没有,您可能正在阻止UI线程,这将使ProgressBar在任务完成之前不会更新。要在我的类中实现INotifyPropertyChanged,需要做什么?顺便说一句,我通过任务打开了此传输仅此:
公共类WiresharkFile:INotifyPropertyChanged
我可以看到NotifyPropertyChange方法,但我看不到INotifyPropertyChanged接口?!查看我的WiresharkFile类更新即使文件位于ObservableCollection内,WiresharkFile也需要实现INotifyPropertyChanged,以便其他类知道它们可以支持其更改。但除此之外。。。这可能是一个愚蠢的问题,但是,您是否使用异步调用?如果没有,您可能正在阻止UI线程,这将使ProgressBar在任务完成之前不会更新。要在我的类中实现INotifyPropertyChanged,需要做什么?顺便说一句,我通过任务打开此传输仅此:
公共类WiresharkFile:INotifyPropertyChanged
<ListView.Resources>
    <DataTemplate x:Key="MyDataTemplate">
        <Grid Margin="-6">
            <ProgressBar Name="prog" Maximum="100" Value="{Binding Progress}" 
                         Width="{Binding Path=Width, ElementName=ProgressCell}" 
                         Height="20" Margin="0" Background="#FFD3D0D0" Style="{StaticResource CustomProgressBar}" />
            <TextBlock Text="{Binding Path=Value, ElementName=prog, StringFormat={}{0}%}" VerticalAlignment="Center"
                       HorizontalAlignment="Center" FontSize="11" Foreground="Black" />
        </Grid>
    </DataTemplate>
    <ControlTemplate x:Key="ProgressBarTemplate">
        <Label  HorizontalAlignment="Center" VerticalAlignment="Center" />
    </ControlTemplate>
</ListView.Resources>
foreach (WiresharkFile item in files)
{
    item.Progress = item.Progress;
}