我尝试将我的对象绑定到ListView
并且这不起作用,这个对象是从另一个继承的,所以我的怀疑是maby我尝试另一种方式或者我错过了一些东西。
这就是我的全部内容:
此对象代表WiresharkFile,我尝试支持多种格式,因此每个格式文件都具有以下属性:
进度(百分比)
公共抽象类WiresharkFile { protected string _fileName; protected int _packets; protected int _packetsSent; protected string _duration; protected double _speed; protected int _progress;
public string FIleName
{
get { return _fileName; }
set { _fileName = value; }
}
public int Packets
{
get { return _packets; }
set { _packets = value; }
}
public int PacketsSent
{
get { return _packetsSent; }
set { _packetsSent = value; }
}
public string Duration
{
get { return _duration; }
set { _duration = value; }
}
public double Speed
{
get { return _speed; }
set { _speed = value; }
}
public int Progress
{
get { return _progress; }
set { _progress = value; }
}
}
这是我的列表视图:
<ListView ItemsSource="{Binding wiresharkFiles}" >
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource ListViewHeaderStyle}">
<!-- file name column -->
<GridViewColumn Width="485" Header="File name" DisplayMemberBinding="{Binding FileName}" />
<!-- speed column -->
<GridViewColumn x:Name="SpeedCell" Width="130" Header="Speed" CellTemplate="{StaticResource MyDataTemplate2}" />
<!-- duration column -->
<GridViewColumn Width="100" Header="Duration" DisplayMemberBinding="{Binding Duration}" />
<!-- packets column -->
<GridViewColumn Width="100" Header="Packets" DisplayMemberBinding="{Binding Packets, StringFormat={}{0:#,0}}" />
<!-- packet sent -->
<GridViewColumn Width="100" Header="Packets sent" DisplayMemberBinding="{Binding PacketsSent, StringFormat={}{0:#,0}}" />
<!-- progress column -->
<GridViewColumn x:Name="ProgressCell" Width="60" Header="Progress" CellTemplate="{StaticResource MyDataTemplate}" />
</GridView>
</ListView.View>
</ListView>
我的Collection
包含所有这些对象:
声明:
ObservableCollection<WiresharkFile> wiresharkFiles;
在委托人之后:
wiresharkFiles = new ObservableCollection<WiresharkFile>();
this.DataContext = this;
现在从我的主要内容中创建新对象:
WiresharkFile wiresharkFile = new Libpcap("file name");
wiresharkFile.ReadFileDetails(); // this read the file and count how many packet contain, duration...
wiresharkFiles.Add(wiresharkFile);
此Libpcap
继承自WiresharkFile
:
public class Libpcap : WiresharkFile...
所以在这一点之后我的abject在Collection
内,但我仍然无法在ListView
内看到这一点。
我也试着看看try-catch如果扔掉除外但没什么。
答案 0 :(得分:0)
你可以尝试
wiresharkFiles = new ObservableCollection<WiresharkFile>();
//this.DataContext = this
this.DataContext = wiresharkFiles;