myHealth - Rudi Grobler

myHealth

I recently had a friend of mine (who is a professional bodybuilder), ask me to write him a simple application with which he can track his training progress?

Here is some of the things I learned while writing myHealth

INotifyPropertyChanged vs DependencyObject

The PropertyGrid I used unfortunately only work with dependency properties (DependencyObject) so I had to choose them! My personal preference would have been the lighter weight INotifyPropertyChanged. Here are the pro's and con's of both

DependencyObject

- .NET 3.0 or better

- Can't be serialized (THIS SUCKS)

- Extra overhead (Dispatcher)

+ DependencyProperty Features: Coercion, Property changes notification, Spars storage, Validation, optimized for data binding, etc

INotifyPropertyChanged

+ .NET 2.0 or better

+ Serializable

+ Lightweight

When select between DependencyObject vs INotifyPropertyChanged, you should also put it into context of where it would be used... Are you creating a Model, Business Object, Domain Object, etc... Some of the cons don't then apply!

Although I was forced to use DO's, the fact that I had to manually store my data was a huge pain in the ...

Check out the full discussion on the WPF Disciples news group

PropertyGrid

I used Denis Vuyka's excellent PropertyGrid! The only drawback of using this PropertyGrid was that it only worked with dependency properties! To use the PropertyGrid, add the following namespace

xmlns:dv="clr-namespace:DenisVuyka.Controls.PropertyGrid;assembly=DenisVuyka.Controls.PropertyGrid"

and use it as follows

<dv:PropertyGrid SelectedObject="{Binding Path=SelectedItem, ElementName=assesmentsListBox}" ExpandCategories="False" />

The SelectedObject can be any DependencyObject derived class, here I bind it to the current selected Assesment.

The category header is determined by the following attribute on the DP CLR Property wrappers

[Category("Assesment")]

IsolatedStorage

myHealth uses IsolatedStorage (Domain) as the storage medium for the assesment history

IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForDomain();
IsolatedStorageFileStream stream = newIsolatedStorageFileStream("assesments.xml", FileMode.Open, file);

Drag & Drop

Drag & Drop in WPF is extremely easy... I added the following to my window

AllowDrop="True" 
Drop="Window_Drop" 

And here is my Drop event handler

private void Window_Drop(object sender, DragEventArgs e)
{
    string[] fileNames = e.Data.GetData(DataFormats.FileDrop, true) as string[];

    foreach (string fileName in fileNames)
    {
        ...
    }
}

Now you can drag & drop pictures into myHealth!!!

TODO: Check the file extension of file being dropped... make sure that it is a .JPG file!!!

Structural Skinning

myHealth also supports structural skinning. I am currently creating a extra skin using Blendables Timeline layout panel which will lay out the assessments on a timeline!

DrawingBrush

myHealth uses a DrawingBrush as the default background for the progress pictures ListBox... This is similar to what popular programs like Blend use.

Zoom, Zoom, Zoom...

The Zoom is a simple UIElement binding between the Slider.Value and the ScaleTransform.X and ScaleTransform.Y of my images in my ListBox!

Code Analytics

Source Analysis (StyleCop) is a new product recently released by Microsoft. Although only recently released, this product has been used internally by Microsoft for years! The program helps enforce uniform and easily maintainable code! Since myHealth will be released on CodePlex, I decided to give it a try...

Disabled the following rules:

  • C# -> Analyze design files

These files are created by Visual Studio...

  • C# -> Ordering Rules

SA1201

  • C# -> Readability Rules -> Method Parameter Placement

SA1115, SA1116, SA1117

Dr WPF's dependency property snippets current violate these rules...

  • C# -> Documentation Rules -> Element Documentation

SA1600

  • C# -> Documentation Rules -> File Headers

All

Source

The source is released on CodePlex

kick it on DotNetKicks.com
Published Monday, June 23, 2008 9:11 AM by rudi
Filed under: , ,

Comments

# myHealth

You've been kicked (a good thing) - Trackback from DotNetKicks.com

Monday, June 23, 2008 9:18 AM by DotNetKicks.com

# re: myHealth

looks cool Rudi

Monday, June 23, 2008 9:27 AM by sacha

# re: myHealth

Tnx Sacha...

Monday, June 23, 2008 9:40 AM by rudi

# re: myHealth

Hi Rudi,

When I run myHealth I get this prompt: "This project includes a password-encrypted key used for signing.  Enter the password for the key file to import the key file into the local crypto-store database for use.

Key file: MyHealth_TemporaryKey.pfx"

What is the password, or what do I need to do to get it to run?

Chris

Monday, June 23, 2008 5:58 PM by Chris

# re: myHealth

Sorry about that, I think you should be able to just delete the .pfx file and recompile? The IsolatedStorage required signing...

Monday, June 23, 2008 8:08 PM by rudi

# re: myHealth

Hi Rudi, thanks, I tried that, it runs, but there is no data and the menu items are greyed out.  I can import, but, I don't know what to import.  I would love to study this application ...

Best regards,

Chris

Monday, June 23, 2008 10:32 PM by Chris

# re: myHealth

Hi Chris...

Sorry, will explain the use more on the CodePlex site... the basics is that you can take any photo and drag it onto the surface of the application... this then create a assesment object that you can modify by using the property grid! You can also import pictures using the menu option!

This is a very simple way to tag photos but can easily be extended to tag photos with other information! Currently I only tag the photos with trainging info (ie. body fat, weight, calve, bicep, chest size, etc...

But the concept is pretty simple and can be extended... also know that it follows the MVC pattern... read more about this on codeplex (Josh has excellent material on the subject)

Hope you find it useful...

If you have any more questions, please ask! Its the only way I can get my program and blog better!

Rudi

Tuesday, June 24, 2008 5:08 AM by rudi

# re: myHealth

Thanks Rudi!  That did the trick!  I did have one other question ... awhile back you did a post on "Keep track of open windows in WPF" dotnet.org.za/.../keeping-track-of-open-windows-in-wpf.aspx

I am considering using this approach on a new WPF project I am working on.  I got the classes to compile and all, but, I am not sure how to hook it all up.  I was wondering if you had your sample application available for download or if you could email it to me at chris.russi AT pacificlife DOT com

Best regards,

Chris

Tuesday, June 24, 2008 4:23 PM by Chris

# "Serialize" a DependencyObject

In my previous post , I mentioned that my biggest gripe with deriving from DependencyObject is that it

Tuesday, June 24, 2008 7:58 PM by Rudi Grobler

# Link Listing - June 25, 2008

Link Listing - June 25, 2008

Thursday, June 26, 2008 6:54 AM by Christopher Steen

# Link Listing - June 25, 2008

ASP.NET Using routing with ASP.NET web forms apps [Via: luisabreu ] WPF myHealth [Via: rudi ] "Serialize"...

Thursday, June 26, 2008 6:55 AM by Christopher Steen