Storage and naming of log data

I’m in the process of rewriting a small application from console mode to a GUI mode.

The input is a file with log data from a measuring device:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>...
00029;00044;00076;00044;00021
00309;00032;00037;00000;65535
00013;00016;00008;00007;00005
...
</code>
<code>... 00029;00044;00076;00044;00021 00309;00032;00037;00000;65535 00013;00016;00008;00007;00005 ... </code>
...
00029;00044;00076;00044;00021
00309;00032;00037;00000;65535
00013;00016;00008;00007;00005
...

Each row of data represents 5 counters which summarize the range in which the measure fell, i.e. first column is “<40%”, 2nd column is “[40-50[“, and so on…

First row as example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>29 counts below 40% | 44 counts between 40% and 60% | 76 counts between 60% and 80%
44 counts between 80% and 90% | 21 counts between 90% and 100%
</code>
<code>29 counts below 40% | 44 counts between 40% and 60% | 76 counts between 60% and 80% 44 counts between 80% and 90% | 21 counts between 90% and 100% </code>
29 counts below 40% | 44 counts between 40% and 60% | 76 counts between 60% and 80%
44 counts between 80% and 90% | 21 counts between 90% and 100%

In the console application I used an array of integers to store each data row, putting each row array in a list. So far, so good… The application then used a for-loop to print out the values with descriptions to the console.

My problem: I wanted to create a GUI with WPF and apply databinding.

But I have a conceptual issue with how to create the data binding to the arrays of integers and visual elements.

I have not had problems with data binding to single properties. The challenge is due to the arrays.

I think I should create a class like this (could also be used as a ViewModel):

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class CounterRecords
{
public List<CounterRecord> DataRecords { get; set; }
}
</code>
<code>public class CounterRecords { public List<CounterRecord> DataRecords { get; set; } } </code>
public class CounterRecords
{
    public List<CounterRecord> DataRecords { get; set; }
}

But how should I go about the CounterRecord class?
What’s a clean / clear implementation of this object that I can bind to?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public class CounterRecord
{
public int Range40 { get; set; }
public int Range40_60 { get; set; }
public int Range60_80 { get; set; }
public int Range80_90 { get; set; }
public int Range90_100 { get; set; }
}
</code>
<code>public class CounterRecord { public int Range40 { get; set; } public int Range40_60 { get; set; } public int Range60_80 { get; set; } public int Range80_90 { get; set; } public int Range90_100 { get; set; } } </code>
public class CounterRecord
{
    public int Range40 { get; set; }
    public int Range40_60 { get; set; }
    public int Range60_80 { get; set; }
    public int Range80_90 { get; set; }
    public int Range90_100 { get; set; }
}

3

The Model layer should reflect your data, so if your log data represents 5 separate values which indicate a counter of a range, then that’s what your Model should look like.

Your CounterRecord data model looks fine to me, however some things to take into consideration when using WPF’s data binding systems are:

  • Are you going to be modifying the CounterRecord at runtime, and does this change need to be reflected in the UI? If so, you need to implement INotifyPropertyChanged on your CounterRecord class so it notifies the UI whenever it gets updated

  • Are you going to be modifying the collection of CounterRecord objects at runtime, and does this change need to be reflected in the UI? If so, you will want to use an ObservableCollection instead of a List<T> for the same reasons

To bind to a collection instead of a single property, you’ll want a UI control with an ItemsSource property, such as a DataGrid or an ItemsControl

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><DataGrid ItemsSource="{Binding DataRecords}" />
</code>
<code><DataGrid ItemsSource="{Binding DataRecords}" /> </code>
<DataGrid ItemsSource="{Binding DataRecords}" />

or

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code><ItemsControl ItemsSource="{Binding DataRecords}" />
</code>
<code><ItemsControl ItemsSource="{Binding DataRecords}" /> </code>
<ItemsControl ItemsSource="{Binding DataRecords}" />

Basically, an ItemsSource binding will loop through your collection and create a UI element for each item in the collection. That UI element may be a DataGridRow, a TabItem, a ListBoxItem, or even some custom element that you define with an ItemTemplate.

If you’re interested, my blog has a better explanation of an ItemsControl than MSDN has, and it will probably help you understand the binding process to collections a bit better.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật