我有WPF application
我正在使用PcapDotNet DLLs
通过packets
发送Networkcard
。
这是我的代表Wireshark file
的对象:
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; }
正如您在每个文件中看到的那样,我正在计算Progress
。
现在我的所有文件都在ListView
内,而ListView
我有Progress-Bar column
。
这是我的Progress-Bar风格:
<!-- Progress-Bar style -->
<Style x:Key="CustomProgressBar" TargetType="ProgressBar" >
<Setter Property="Template" >
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
<Border BorderBrush="Transparent" BorderThickness="1" Background="LightGray" CornerRadius="0" Padding="0" >
<Grid x:Name="PART_Track">
<Rectangle x:Name="PART_Indicator" HorizontalAlignment="Left" Fill="#FF15669E" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我的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>
因此,当Wireshark file
正在进行中时,我可以看到它发送packets
并且属性发生了变化,但Propress-Bar
仍然在0%
。
所以我做了一点测试,在timer event click
里面改变了我的WireshakFile
Progress
属性,在这种情况下我可以看到我ListView Progress-Bar
的变化。
所以我的问题是我做错了什么?
修改
我也尝试了一些看起来非常奇怪的东西,但这是在讨论:
在我的Timer_Tick
内,我尝试遍历我的ObservableCollection
集合:
foreach (WiresharkFile item in files)
{
item.Progress = item.Progress;
}
正如你所看到的,它只是指向同一属性,但这是有效的。