Latest News
- LongListSelector – Windows Phone 7 development
- Windows Phone 7 development
- Use Bing Maps SetView method with MVVM – Windows Phone 7
- Telenet telemeter for Windows Phone 7
- Windows Phone 7 development
- QR Code generation
- Our Katalungan Guro Jan Van den Borne showing some Kali techniques
- HTPC: Part 2 – The software
.Net 18-200mm Aleksi Bricolet Anime Arcadia Benjamin Carre bwards C# Captain Harlock Clothing Comics Computer Cycling D40x Don Figueroa Eskrima Eye candy Fake Flickr HTPC iPod iTunes iWatchSyncer LightRoom Magic the Gathering Music mvvm Nicolas Ferrand Nikon Photography Photoshop Polar SB-600 Spaceships Spawn Star Wars Tilt-shift Transformers Trek Typing Visual Studio Voxel windows phone 7 wp7 wp7contrib
Categories
Blogroll
Blogroll
Pictures
Programming
LongListSelector – Windows Phone 7 development
Posted on October 24, 2011
If you are using a Windows Phone 7, you’ll have noticed that when you want to go through your People list they are all ‘grouped’ by one character. And when you press one of those characters, you’ll get a nice overview of all available groups, again shown by a character.
Example
Now if you are a wp7 developer and want to have the same kind of behaviour for any kind of ‘lists’ you want to present to the enduser, you have 2 options, 1. develop your own control or 2. use the LongListSelector available in the Sliverlight toolkit for WindowsPhone7!
Now to use this control, you better read up 2 posts available on windowsphonegeek
Now if you follow these posts, you’ll notice you won’t get the same look and feel as on the People list in the Windows Phone itself… now to overcome this, you’ll better read up Benjii’s post on how to use the LongListSelector!
Because when you follow his instructions, you’ll get a better UI in reference to the People list on the Windows Phone.
But somehow when I used his solution, I was not able to get a correct Item Selection Change event to Command working. Somehow Benjii’s group class won’t let me cast back to one selected item in the ViewModel.
So again I needed a solution! And after some twitter chatter and a question on stackoverflow, I was directed to a custom implementation done by Claus Jørgensen!
The best way to look at his grouping class and LongListSelector usage, is to download his weather app from GitHub!
It contains a fine example on how to use the LongListSelector and also an extension that is needed to get Command binding to the SelectionChanged event!
His Grouping class also makes it possible to get the correct item from when the selection changed event get’s fired!
I did however change one small detail of his Grouping class ( LongListCollection.cs ), because when you do nothing with Claus’ class, you’ll only see the item group keys of the available items. And Benjii’s solution, first add’s dummy key/list items so that you’ll get the same overview as on the People list, when a group has no items the group key will be greyed out!!
To get this working with Claus’ class, I added a DefaultHeaders list! Here is my implementation of the class:
namespace DepSoft.Mobile.WP7.Model
{
public class LongListCollection<T, TKey> : ObservableCollection<LongListItem<T, TKey>>
where T : IComparable<T>
{
public LongListCollection()
{
}
public LongListCollection(IEnumerable<T> items, Func<T, TKey> keySelector, List<TKey> defaultHeaders)
{
if (items == null)
throw new ArgumentException("items");
var groups = new Dictionary<TKey, LongListItem<T, TKey>>();
this.FillGroup(groups, defaultHeaders);
foreach (var item in items.OrderBy(x => x))
{
var key = keySelector(item);
if (groups.ContainsKey(key) == false)
groups.Add(key, new LongListItem<T, TKey>(key));
groups[key].Add(item);
}
foreach (var value in groups.Values)
this.Add(value);
}
private void FillGroup(Dictionary<TKey, LongListItem<T, TKey>> groups, List<TKey> defaultHeaders)
{
foreach(TKey key in defaultHeaders)
{
if(!groups.ContainsKey(key))
groups.Add(key, new LongListItem<T, TKey>(key));
}
}
}
public class LongListItem<T, TKey> : ObservableCollection<T>
{
public LongListItem()
{
}
public LongListItem(TKey key)
{
this.Key = key;
}
public TKey Key
{
get;
set;
}
public bool HasItems
{
get
{
return Count > 0;
}
}
public Brush GroupBackgroundBrush
{
get
{
if (HasItems)
return (SolidColorBrush)Application.Current.Resources["PhoneAccentBrush"];
else
return (SolidColorBrush)Application.Current.Resources["PhoneChromeBrush"];
}
}
}
}
Now if you want to use this in your ViewModel, you only need to add the following 2 lines:
List<char> defaultHeaders = new List<char>("#abcdefghijklmnopqrstuvwxyz");
this.ListGroup = new LongListCollection<iBaseItem, char>(albumList.Cast<iBaseItem>(), c => c.GroupHeader[0], defaultHeaders);
I hope you guys have as much fun with the LongListSelector as I did
- SelectionChangeCommited event on Combobox not triggered
- Serialize/Deserialize objects in .Net – don’t forget to initialize
- Night of Martial Arts
Windows Phone 7 development
Posted on May 9, 2011
Currently I released 2 Windows Phone 7 apps to the Microsoft Marktplace. The creation of both apps was not that difficult, because when you want to develop for wp7, there are several good reusable libraries out there!
Let me zoom in on one in particular, called WP7Contrib! It’s a wp7 library that is available on CodePlex, so the sourcecode is also available! But why am I using it, well let me give you some examples.
* Tombstoning
Each time your wp7 app gets tombstoned, there is a great chance you’ll want to ’save state’, this helps the user experience of your app. There are several good examples out there that handle this, but I like the implementation of it in wp7contrib.
Basically you’ll create a new ViewModelBase class that implements 2 methods: IsBeingActivated(IStorage storage); and IsBeingDeactivated(IStorage storage); Now when you create a ViewModel, you’ll inherit from this base class, and because wp7contrib has a StorageService that gets passed along as parameter, you can use it to Write and Read data to/from it!
So each time an app gets tombstonded the IsBeingDeactivated method is called on each instantiated ViewModel, enabling you to write code like this: storage.Write(“zoomLevel”, this.ZoomLevel); This example will write the current value of a local property to the StorageService and when the app resumes you can put following code in the IsBeingActivated method: this.ZoomLevel = storage.Read
And presto, your View will again contain the data the user had put in before tombstoning!
* Isolated Storage
A similar feature is a nice wrapper around the Isolated Storage called StoreSettings. It gives you some method calls that are easy to use! Some examples:
- this.SettingsService.Write
- this.SettingsService.TryToRead
* Page navigation
Page navigation from ViewModels in a MVVM app is something that needs to be addressed correctly! Because when you want to submit an app to the marktplace, this is something that has to be working 100% and there are even some rules applied to it.
My tip, just use the NavigationService available in wp7contrib! If you want to ‘navigate’ to another view from your viewmodel, you’ll only have to add following code: this.SettingsCommand = new RelayCommand(() => this.NavigationService.Navigate(ViewModelLocator.SettingsPageUri));
Side note here, I’m setting up a RelayCommand in the constructor of the ViewModel, so that I can trigger this from an appbarbutton in the View!
* Bing Maps location
One last item that I’m a huge fan of in this wp7contrib lib, is the LocationService! One of my apps has Bing Maps integrated and when you need to get a current location fix ( or you want to track location for a period of time ), again you’ll have to write a lot of code to get it done ‘right’.
But with wp7contrib you’ll only need to call the correct methods and everything will be handled for you!
In my app I current allow the user to get his current location fix from the push of an appbar button, with this I’m triggering following code:
_currentSubscriber = _locationService.Location()
.ObserveOnDispatcher()
.Subscribe(location => this.CurrentPosition = location);
What it does, is fire up the location service and return the current phone location if it is available! When I get it, I’ll just set the CurrentPosition, what in my app is a MVVM binded property to a pushin on the BingMaps control in my view… and presto the current location is visible!
There are also some cool controls available and the one I like most is the SmartTextBlock, just take a look here for the implementation.
Well the list could go on, but currently these 4 are my mostly used ones! I just have to say that wp7contrib helped me speed up my wp7 app development and I would suggest you’ll check it out.
It is available on the wp7contrib codeplex site and the main page contains a good overview of most of the features.
Use Bing Maps SetView method with MVVM – Windows Phone 7
Posted on March 16, 2011
Well when you are developing on the Windows Phone and are trying to use MVVM, you’ll notice not everything is ‘real’ MVVMable
You’ll notice it mostly when you are using controls that don’t have much bindable items… so sometimes you’ll loose control of the View – ViewModel link.
An example I came across, where I was stuck with using the normal MVVM way, was when I added some pushpins on a Bing Maps control and wanted to adjust the view of the Bing Maps so that it would show all pushpins just added!
There is a real nice method on the Bing Maps called SetView()! It accepts a LocationRect as parameter and you can create such a LocationRect from a IEnumerable list of Geocoördinates. In other words if you have the PushPin collection, you can pass this along and the Bing Map will zoom and center to an appropriate size / place to show all pushpins in the given collection.
But the bad part, the SetView is a method and there is no bindable property on the map to use to control this. So you are a bit stuck when you only want to use the MVVM pattern.
So how to solve this, well it’s actually very easy
When you are using the MVVMLight Toolkit from Laurent Bugnion, you can use the Messaging feature for this!
So what do you need to do.
First create a class inside the Model folder ( or in the root of the project ) called PushPinModel and add a List<Geocoordinate> GeoCoordinateList property inside of it.
Then assuming you have a MainPage View, add following in the constructor of this MainPage.xaml.cs
Messenger.Default.Register<PushPinModel>(this, action => this.SetView(action));
Also add following private method inside the MainPage.xaml.cs, this method will be called each time the listener receives a message!
private void SetView(PushPinModel pushpinModel)
{
if (pushpinModel.GeoCoordinateList.Count > 0)
{
this.PointMap.SetView(LocationRect.CreateLocationRect(pushpinModel.GeoCoordinateList));
};
}
Now the only thing left to do is fill up this Geocoordinate list in the ViewModel and send out a message to the listeners!
PushPinModel pm = new PushPinModel();
pm.GeoCoordinateList.Add(new GeoCoordinate(51.10524, 4.54229));
pm.GeoCoordinateList.Add(new GeoCoordinate(51.3411, 3.2398));
Messenger.Default.Send<PushPinModel>(pm);
For a detailed example just download changeset 62756 from my WP7 codeplex project wp7cycling.codeplex.com
Similar postsTelenet telemeter for Windows Phone 7
Posted on March 14, 2011
Well, maybe you noticed when reading my last post… I’ve been busy developing for my Windows Phone 7!
The best way for me to learn a new environment is to try out some real scenario. This way I have a good focus on what I’m trying to do/learn.
So also when I started with WP7 development, I had an idea I wanted to work out and that idea was to create a Telemeter ( Telenet bandwidth usage tool ) for the Windows Phone.
At first, it was not easy to get this thing going… Everything was actually new for me! XAML, MVVM, Silverlight controls many different things!
But in the end, I’m glad I did take a look at this platform, because I think it has lot of potential!
So for the app itself, I just got notice today it passed Microsoft certification, so I guess it will be downloadable soon from the Marktplace.
When you start up the app for the first time, you’ll need to enter your Telenet credentials ( the actual first account given, not aliases you created yourself afterwards ) in the settings screen.
After that, you’ll be able to refresh the data graph available on the main screen… when everything goes well ( sometimes the Telenet service is not available ), you’ll get a nice looking graph with all the bandwidth details of each day.
But an image says more than words, so here is a preview of the app itself.
[Update] It’s downloadable http://www.appsfuze.com/applications/windowsphone.tools/wp7telemeter,9329
- Windows Phone 7 development
- Polar RS800cx PTE settings – part 1 – Using a speed or cadence sensor
- Polar ProTrainer 5 – Average speed readout
Windows Phone 7 development
Posted on March 3, 2011
Well my current cellphone is a new HTC smartphone with the Window Phone 7 OS! It’s the HTC Trophy and I have to say the OS and the device are just brilliant.
But to be honest, the fact that you can just code .Net apps for it, made it a winner in my books.
So let me introduce you in the Windows Phone 7 development area.
Here are some of my current findings with it.
The first thing to know is that when you are developing it will be in a WPF/Silverlight environment, so be sure to get the hang of XAML or even better, get your Expression Blend skills up to date.
Secondly, the best way to create good, manageable code, is by using the MVVM pattern. The fact that this pattern is not only restricted to the Windows Phone 7 environment makes it beneficial to learn it for other projects. MVVM is based on viewmodel property binding for your view data.
Now to get a good start with MVVM, you better use a framework that integrates well with the Windows Phone 7. My personal favourite is MVVM Light Toolkit from Laurent Bugnion!
Get the details here: http://www.galasoft.ch/mvvm/getstarted/ and here: http://mvvmlight.codeplex.com/.
The only drawback in my mind, is the fact that currently you are by default limited in possible api uses from the Phone itself. In other words, some of the nice controls or features used on the default up front installed phone apps are not available to the developers. So another good thing to know is what frameworks/libraries are out there to overcome this…
My current list of libraries are
* Silverlight for windows phone toolkit: http://silverlight.codeplex.com/
* Coding4Fun windows phone toolkit: http://coding4fun.codeplex.com/
* WP7 Contrib framework: http://wp7contrib.codeplex.com/ ( this is actually already a superset of other libraries with custom additions )
When you add these to your Windows Phone 7 tool set, you’ll get plenty of controls and helpers that are needed when you start developing.
To show of some of the features of these frameworks I started a CodePlex project, called WP7Cycling! http://wp7cycling.codeplex.com/
The main reason for this project is just for myself to get to know the development environment, but it will also benefit other developers in showing what can be done in combination with the given toolkits!
For now it doesn’t have any downloads, so just grab the source code to get the complete project if you want to see it running in the emulator: http://wp7cycling.codeplex.com/SourceControl/list/changesets
Currently I created a simple MainPage with an integrated Bing Maps control and when you press the Get current location button on the appbar, the map will center itself on the current GPS coordinate location of the phone.
Have fun coding and any tips or tricks are always welcome
- Telenet telemeter for Windows Phone 7
- Use Bing Maps SetView method with MVVM – Windows Phone 7
- Windows Phone 7 development
QR Code generation
Posted on October 26, 2010
For some time now, most people here in Belgium are beginning to notice the new bar code thing that is popping up all over the place… I’m talking about QR codes!
They are not difficult to spot, because of there special resemblance. But it’s not the fact that they are more advanced in resemblance that makes them useful It’s the fact that they can contain data value and data metadata!!
In other words not every QR code represents the same thing… you can have it represent:
- Text
- Website URL
- Telephone Number
- SMS Message
- Email Address
- Email Message
- Contact Details (VCARD)
- Event (VCALENDAR)
- Google Maps Location
- Social Media ( like a facebook profile )
And accordingly to the content type your mobile phone or computer will perform the needed action to represent the data value correctly!
Now most people don’t know exactly how to use these QR Codes, let alone how to generate them… because of this you see service website like this one popping up all over the place.
But the funny thing is, everybody can get these QR Codes for free from a very nice online service! It’s called Google Chart API.
We are currently using it in a small ASP.Net MVC application at our company and we are using it to get Google maps location data represented through a QR Code.
The only thing you need to do is read the instructions up on the Google Chart website here!
You just have to ‘create’ the correct http request url and when ‘executed’ you’ll get back an image.
If you use it correctly you can for instance represent longitude-latitude coördinates on Goolge maps by using following code:
http://chart.apis.google.com/chart?cht=qr&chs=85x85&chl=http://maps.google.com/m?q=51.10231200,4.53204000
This will give you following QR Code, just try to scan it with your iPhone or Android smartphone
Our Katalungan Guro Jan Van den Borne showing some Kali techniques
Posted on September 14, 2010
Kali Belgium from Einchun on Vimeo.
Similar postsHTPC: Part 2 – The software
Posted on September 1, 2010
Let me show you what I’ve done to get my HTPC up and running, through some blogposts.
The drilldown
Part 1: The hardware
Part 2: The software
Part 3: The overall conclusion and some pictures
This part will be about the software that is used on my HTPC to get everything working.
* OS: Windows 7 Home edition 64bit
Because of the fact that I got 4gb of memory, there was only one option and that was installing Windows 7 Home edition 64bit!
It’s a good OS and will serve all my needs.
* Media software: Windows 7 Media Center
With the Win7 Home edition, you’ll get Windows Media Center 7 for free! it’s a great HTPC software tool that already contains many features, but you’ll also be able to install extra plugins.
* Music playback: Windows 7 Media Center & iTunes
I manage all my music in iTunes ( playlists and metadata tagging ), this because I use my iPod Nano during my sport activities! On my HTPC I have a backup running of all my available music, so Media Center will pick this up in the Music hub.
* Picture viewing: Windows 7 Media Center & FastPictureViewer
I own a Nikon D40x and love the quality it produces! To be able to do fine manipulation on my photo’s I tend to save them in RAW format ( Adobe DNG to be precise ). But the Pictures hub of Media Center doesn’t support any RAW format… to accomplish this, you can get the 64bit codec from FastPictureViewer! It works like a charm, now all my RAW pictures are viewable inside the Pictures hub.
* Blu-Ray playback: ArcSoft TotalMedia Theatre 3
TotalMedia from ArcSoft is a solid product when it comes to Blu-Ray playback on Windows… and thanks to the Media Center integrated interface you can now watch your Blu-Rays from inside Media Center itself!
* DvD playback: Media Browser
All my Dvd’s are ripped unto the HTPC. To get a nice interface for different catalogues, I opted for Media Browser… it’s just a great tool with also plugin capability! It can also auto fetch movie information ( metadata, posters and backdrops ) from the internet.
I made a seperate catalogue for general movies and one for my kids .
* Weather information: mceWeather
Great plugin that will show you a nice forecast of the weather of any location!
Another one worth mentioning is HeatWave, but I don’t like the info switching on the main screen.
* CPU temperature: CoreTempMC
A nice little plugin that allows you to keep track of the temperature of your CPU from within Media Center.
Similar postsHTPC: Part 1 – The hardware
Posted on May 20, 2010
Well I finally got around buying a HTPC for my home entertainment needs
It took me a while, but now that it’s here I’m very content!!
Let me show you what I’ve done to get my HTPC up and running, through some blogposts.
The drilldown
- Part 1: The hardware
- Part 2: The software
- Part 3: The overall conclusion and some pictures
This first part will be about the hardware that makes the HTPC work.
* Motherboard: Gigabyte GA-MA785GMT-UD2H
I went for this motherboard for 2 main reasons! One it would work perfectly with my intended CPU ( more later ) and secondly it has all the hardware on board for all the needed Home Theater features!
It has Full HD 1080p Blu-Ray playback capability, a S/PDIF In/Out with support for HD 7.1 channel audio and last but not least it supports DDR3 memory.
* CPU: AMD Athlon II X4 605e
AMD is a good option for building a HTPC, because they have some nice cpu’s that try to keep your power consumption low. Meaning your machine also won’t heat up that much and because of this you don’t need to have high speed ( noisy ) fans! Also with the chosen motherboard I’m able to upgrade to a 6 core AMD if I want. For now I’ve chosen the 4 core 605e, because these e models only have a thermal design power of 45w!!
* Case: Antec NSK2480
I just love the design of this case! It just looks stunning and has enough space to serve my purpose… I wanted to add one normal HD and one SSD ( more on this later ). This case incorporates a 380Watt EarthWatts power supply, so the total consumption of power is regulated!
The only drawback of this case is the absence of a IR receiver… but I didn’t want to buy the Antec Fusion Remote because, this case, has a LCD screen that is not needed in my setup and I also dislike the volume button ( because the sound is regulated through my receiver ).
For some people the silver front could also be a drawback, but I’m not that difficult
* IR Receiver: Antec Veris Multimedia Station Basic
This was the most difficult thing to choose! Because I always thought to use this IR, but I read many ‘problems’ with it on different forums in combination with Logitech universal remotes!! And I own a Logitech Harmony One that I wanted to use in cooperation with the HTPC…
After much reading I decided to still have a go with it and now that the HTPC is in use, I have to say, I can’t complain
I have to admit it takes some setting and tweaking to get it working, but at the end I’m content! ( cfr my second post on software for more settings details )
* Blu-Ray: Lite-On iHOS104
One of the main features my HTPC needed to get was Blu-Ray playback! So to get this working, I needed to install a Blu-Ray drive. I just opted for one of the cheapest Blu-Ray roms because, writing Blu-Ray’s is not something I foresee to be doing on the HTPC.
* Hard disks: Intel SSD 80Gb X-25M and Western Digital Caviar Green 1Tb
For me a HTPC should be available fast and should be reasonable quiet, but also needs to be able to contain a lot of media data! To get best of both worlds I opted for a SSD as primary HD to boot from and a normal HD to store the media on! In time I could get an extra NAS if more storage is needed…
I have to say that a SDD drive to boot from is just fantastic! The speed is enormous, when you see it in action, you just keep wondering why not all pc’s are equipped with a SSD!!! Nothing but positive reactions when running the HTPC on a SSD.
* Memory: 4Gb of DDR3 memory
The motherboard supports DDR3, so went for that. I added 4Gb because the Windows 7 operating system is 64bits so all memory is used and 4Gb is more then enough for a good HTPC.
Well that’s it for the hardware, stay tuned for the software list in the second blog post.
Similar postsLinq to Objects – join or intersect
Posted on December 16, 2009
Thanks to Linq to objects we can have a more sql like coding style in c#. For somebody that has actual sql knowledge, this comes in very handy.
But it seems that several coding methods perform the same task and gives the same result.
So what coding syntax would you prefer?
For example, assume you want to know which items are given in 2 sets?
You could get this list through following code.
string[] filesList1 = System.IO.Directory.GetFiles(@"C:\temp\List1?);
string[] filesList2 = System.IO.Directory.GetFiles(@"C:\temp\List2?);
var fileListEqual = from file1 in filesList1
join file2 in filesList2
on System.IO.Path.GetFileName(file1) equals System.IO.Path.GetFileName(file2)
select System.IO.Path.GetFileName(file1);
var fileListEqual2 = (from fileIpod in filesList1
select System.IO.Path.GetFileName(file1)).Intersect
(from fileDisk in filesList2
select System.IO.Path.GetFileName(file2)
);
Similar posts
- Charts with Asp.net MVC and jQuery through jqPlot
- Cycling update
- Culture sensitivity in List<string> – how to do comparison