绑定我的对象继承到的ListView [英] Bind my object inherit into ListView

查看:151
本文介绍了绑定我的对象继承到的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试BINN我的对象为的ListView 这不工作,这个对象是从另一个所以我suspition继承是莫比我尝试另一种方式或者我失去了一些东西。
这是我所有的东西:

I try to binn my object into ListView and this not working, this object is inherit from another so my suspition is maby i try another way or i missing something. This is all my stuff:

该对象重新present WiresharkFile,我尝试以支持和几个格式,使每一个格式的文件有这样的特性:

This object represent WiresharkFile, i try to support and several format so every format file have this properties:


  1. 文件名

  2. 分组数

  3. 发送的数据包(我的应用程序也送这个数据包使用Pcap.Net)

  4. 持续时间

  5. 速度

  6. 进度(百分比)

  1. File name
  2. Number of packet
  3. Packets sent (my application also sent this packets using Pcap.Net)
  4. Duration
  5. Speed
  6. Progress (percent)

公共抽象类WiresharkFile
{
    保护字符串_filename;
    保护INT _packets;
    保护INT _packetsSent;
    保护字符串_duration;
    保护双_SPEED;
    保护INT _progress;

public abstract class 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>

和我的保存收藏这一切的对象:

声明:

ObservableCollection<WiresharkFile> wiresharkFiles;

而construstor后:

And after the construstor:

wiresharkFiles = new ObservableCollection<WiresharkFile>();
this.DataContext = this;

现在从我的主要有孔虫我创建新的对象:

Now from my main foram i create new object:

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...

所以这点后,我的下贱是这里面收藏但我仍然cannt看到我的的ListView 里面。
我也试着看到的try-catch如果掷EXCETION但没有。

So after this point my abject is inside this Collection but still i cannt see this inside my ListView. I also try to see with try-catch if throw excetion but nothing.

推荐答案

您可以尝试

wiresharkFiles = new ObservableCollection<WiresharkFile>();
//this.DataContext = this
this.DataContext = wiresharkFiles;

这篇关于绑定我的对象继承到的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆