In WPF data binding is fairly consistent, I would even dare to say best that I ever saw. It is easy to do fairly complex things at some cost to way how simpler things are done. Internet is full of examples how to do simple WPF data binding but it surprisingly lacks examples for doing background updates. I tried here to make simplest example that will work with dynamic updates.
Everything revolves around ObservableCollection. In my example this class is inherited within ItemViewCollection class and all “filling” should be done to Items property. I opted to do so with hard-coded data but you can imagine it being done with data from database or any other source.
Once data is shown, it will not be refreshed unless OnCollectionChanged method gets called. Only then update will propagate around. Above we can see how whole collection should be refreshed once Items get cleared and filled again. If you see that ListView does not respond to your changes (e.g. you added some items) there is chance you forgot to call it.
Data itself is stored within ItemViewData class. That class implements INotifyPropertyChanged interface and thus it enables update notifications for selected properties (e.g. Energy and ImageIndex). You could update all properties but updating only those that you actually changed will improve performance. Again, if you changed property and your ListView does not reflect it, you forgot to do notification.
ListView uses binding to “parts” data provider in order to call GetInstance method within item collection (ItemViewCollection). Whatever this method returns get’s treated as rows for ListView control. Our code is responsible for putting right stuff inside (in FillItems method) and for doing it in correct thread (thus Invoke code there). This is all there is to it.
To make things more interesting I added small method (BackUpdate within App.xaml.cs) that updates some values every two seconds (INotifyPropertyChanged.OnPropertyChanged gets triggered here) and every 20 seconds everything gets reloaded from start (thus need for ObservableCollection.OnCollectionChanged).
It might seem complicated when you look at it for first time but once you see full example code these code fragments should make some sense. :)
I already went through motions of installing Mercurial server on Ubuntu. However, that left us with nasty looking URL with hgweb.cgi in it (e.g. http://192.168.0.2/hgweb.cgi/TestRepo/). Can we make it nicer?
We need to edit “/etc/apache2/sites-available/hg” in order to add two highlighted lines (I kept all other lines for clarity):
Next thing to do is enabling Apache’s mod_rewrite module and restarting apache:
sudo a2enmod rewrite
Enabling module rewrite.
Run '/etc/init.d/apache2 restart' to activate new configuration!sudo /etc/init.d/apache2 restart
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.0.2 for ServerName
[Tue Feb 01 09:42:15 2011] [warn] NameVirtualHost *:80 has no VirtualHosts
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 192.168.0.2 for ServerName
[Tue Feb 01 09:42:16 2011][warn] NameVirtualHost *:80 has no VirtualHosts
If everything went fine you should be access your repositories without hgweb.cgi, e.g. http://192.168.0.2/TestRepo/. Not a big change but it does look much better.
On 23rd August, 2008 Lutz Roeder gave .NET Reflector development to Red Gate Software. At that time Red Gate agreed to provide free community version and everything seemed same. There was paid version available with Visual Studio integration but for occasional need you could always count on free one. This is bound to change with 1st March. Red Gate Software decided to require $35 for what was once known as freeware.
I remember .NET Reflector as a great tool for debugging assemblies that you have no source for. It helped me more than once to navigate my way around some obscure bug that would trigger in other people’s library. I will not even mention how much I learned by viewing other people’s code. :)
I will not go into blaming anyone for killing free version of this tool. Lutz was quite in his rights to give it to Red Gate and I assume that Red Gate is allowed to ask money for it. I also think that most of attacks on Red Gate’s forum are unfounded and uncalled for. Reality sucks, learn to live with it. I am just sad that this beautiful tool will leave my toolbox for now.
Will I buy a licence? Maybe some time, but not right now.
[2012-11-07: Licence for .NET Reflector is $95 these days but there is freeware alternative from JetBrains: dotPeek]
When I did redesign of site into blog format some things got lost. I was quite surprised that those files, not linked from my site, were still getting bunch of hits, especially legacy VB 6.0 code. It seems that there are still some people using it.
By popular demand, here is all that code in single archive. Do note that even most youngest code is from 2004 with most of code being even older. I bring you also original descriptions, nothing is modified in any way.
DnDTabControl How to reorder TabPages inside TabControl.
Highlander Detecting already running program and letting first instance know that.
VB.NET 1.1 DLLs
Medo This DLL is compiled version of classes given on these pages and some classes without source code. There is Profile class that lets you save Form position, ListView Columns witdh and more. OleDb class lets you to easily perform one line queries. There are few more CRC algorithms including CRC8. There is also many more classes that can prove to be useful. There are not too many samples now but more of them will come.
VB.NET 1.1 Classes
BigOFD OpenFileDialog class implemented in .NET has small problem. Buffer size is too small to handle more than few hundred files or even less. This replacement was designed to give you direct access to Windows API and to allow custom buffer sizes. It is mostly compatible with .NET OpenFileDialog so no porting problems should occur.
Bitwise This class gives you ability to perform unsigned Shift left, Shift right, Rotate left and Rotate right bitwise operations over Integer and Short (aka Int16 and Int32) data types. This is very usefull in some algorithms that must be implemented in unsigned logic that is currently unupported by Visual Basic.
COM This class can be used to perform read and write operations on serial communication ports (COM). It has basic example until I gather some time to make better one.
CRC-16 This class gives you ability to check data integrity with CRC16 algorithm.
CRC-32 This class gives you ability to check data integrity with CRC32 algorithm.
RC4 This class enables you to crypt your data using fast RC4 algorithm.
Registry VB.NET includes its own vision of registry access. This vision makes everything possible but its drawback is in number of code lines for most simple things. By using this class you can write/read REG_DWORD and REG_SZ data types in one line.
TagItem First ListBox control use in .NET was very confusing for me. Like, I am sure many of you, I used ItemData to fill in ID of somekind. But there is no ItemData in Kansas anymore so “Dorothy” had to find another solution. It took some time to see that new “Items.Add” formula takes Object as argument. From there, everything was downhill. By using Text and ID as an argument, this class can be successfully used to retrieve same information later. One Object argument is added for “just in case” situations.
VB.NET 1.1 Macros
VB6ver Enables you to use VB6 style versioning in .NET enviroment.
Java
DateTime 1.10 When I started to learn Java, its date management model drove me crazy. It was too much complicated for simple calculations. Here is class that enables date/time management in simple .NET alike class.
Road to Java This script is diary of differences I notice while learning Java. It is not complete nor it will ever be but I will work on it.
VB 6.0 Classes
APIFile This class was developed to open files via API which has advantage of being able to trim them by using Length property.
CRC32 This class gives you ability to check data integrity with standard CRC32 algorithm.
SHA-1 This class enables you to encrypt your passwords with SHA-1 hash (one-way) algorithm.
Window You can enumerate open windows by using this class.
XY This class enables you to draw in X-Y coordinate system. Usefull for drawing mathematical functions graphs.
VB 6.0 Controls
CmnDlg Complete substitude for CommonDialog control. No .ocx needed.
Contain This control can be used as container for other controls.
Progress Complete substitude for ProgressBar control. No .ocx needed.
TextComplete This control gives you AutoComplete ability.
TrayIcon This control gives you option to show icons in Tray notification area.
VB 6.0 Modules
Browse This module enables you to show Browse dialog.
CRC16 This module gives you ability to check data integrity with standard CRC16 algorithm.
CRC32 This module gives you ability to check data integrity with standard CRC32 algorithm.
Date This module enables you to find out when is Easter.
HrBox This module enables you to show Croatian MsgBox and InputBox.
RC4 This module enables you to crypt your data using fast RC4 algorithm.
Registry This module enables you to access Windows registy.
SHA-1 This module enables you to encrypt your passwords with SHA-1 hash (one-way) algorithm.
Shuffle This module contains functions for shuffling elements of zero-based arrays (for playlists, cards, etc.).
ShutDown This module enables you to shut down your computer or put it in sleep mode from your program.
Swap This module enables you to Swap variables in single instruction.
I got new monitor for my Windows Media Center machine and I stumbled upon curious issue.
I control this machine via on-screen keyboard and on new monitor it’s window was too small and of course there was no way of resizing it. That is, there was no GUI way of resizing it. I could always try to resize it programatically with a little help of SetWindowsPos function.
It was as simple as running on-screen keyboard, getting monitor it is on (in order to calculate size, it is not really a must) and then resizing it to desired size:
As far as size is concerned I opted for 40% of screen width (width / 2.5) and 40% of that was to be assigned as height. Exact numbers are not really important but those were ones that I liked the most. It was enough to run this program only once since Microsoft’s On-screen Keyboard will remember previous size upon exit.
If you need bigger on-screen keyboard for Windows XP, try it.