WPF is really awesome!

Today, I had the great experiance of leaving the office with a feeling of, “Oh my God, IT WORKS”!

First of all, dealing with a graphical user interface in Java can be a pain in the butt.  Let me first write up an example in code:

JFrame f = new JFrame()  //This is my window that I want to place everything in.
f.setBackgroundColor(Color.Blue); //This should work, right?  wrong!!!  

Even though the JFrame has a background color property and you think you should be able to do it this way, you actually cannot set the background color of the window in this way.  The proper code would be:

JFrame f = new JFrame();

It is first necessary to get the pane where the content is going first before you can set the background property.  To the newbie in Swing, this is a nightmare.  You set a property that you think should have the desired effect, but you end up wasting a great deal of time searching for the correct object to set one specific property that you think should go quickly.  This is often not taken into account when coming up with time tables and figuring out how long a certain project should take to develop.  Of course if the developer is experienced and knows all of these crazy things, or of the newbie programmer has the best book on Java Swing (THANKS MOM!!!!) currently available, then that time can also be minimal.

My experience in WPF today was extremely favorable.  First off, I did not have 1 issue setting a property.  If the specific property was available to me, it did something when I changed it.  It may not have done what I thought it did, and I may have had to change a different property in another object, but it still did something.  I did not have to wonder what I did wrong, and in many cases the error messages that I got where enough to send me in the correct direction.  This above any other point leads me to the conclusion that I have been working with the wrong GUI for the past three years.  And if the GUI was wrong, then I am wondering if I am using the correct language.  For as much as C# can be confusing and not very intuitive, and for as much as I may not like having to look up the correct DLL file to import in order to reference the class I want, I must say that this alone is a reason to make a fundamental switch in regards to my preferred programming language.  One last thing I have to say, is that the GUI looks GREAT and I am horrible at front end design.  I mean horrible!

My goal for today was to create a front end where it would be possible for new apprentices to write there reports in a program installed on their local machines.  At the moment, they are all using a [Lotus] Notes database installed on a domino server.  Although this sort of setup is not wrong, and even safer than installing everything locally, it is still not optimal because they only use one or two Notes/Domino applications and they do not always want to start up the Notes Client ( a thirty second start on a really good day, two minutes on a normal day, and ten minutes on a bad day) just to make a quick one minute change to a document which tracks their weekly activities for the appropriate agency.  Let’s face it, none of us wants something like that.

Today, I started this front end.  My job is primarily to get myself situated with WPF development in the hopes to be a choice to help the development of a program for company X.  The form that I am basing this front end on is not really busy or anything, there is the typical data that needs to be stated, such as for which dates this particular document will be used for, names, departments, and a block where the user can input what they did that week.  It is really simple and that made it ideal for a first try.  Opening up the main window resembles a word document where the user sees a normal page sized white area in the center, and on the left is an area with tiles that can be pressed in order to open the document that should be opened.  This makes for everything to be pretty simple without much extras.  I do plan on extending this GUI to be able to use drag and drop functionality to open other documents and so on.  As I said, this is only phase 1.

Basically, I am so impressed because I could go into Visual Studio today with a basic idea of what I wanted to do today and without any issues at all, I could effectively design this program and come up with a great prototype to show the bosses at the end of the day and say, “This is what I could do in nine hours time with almost no foreknowledge! This is something that has been sorely lacking in the past year.

All of this being said, I am really contemplating starting BudgIt completely over again, and making a brand new Windows based application where I can truly make use of the great things that WPF has to offer.  Even if this does limit the “customer” base to those who have a windows machine, I do not see that as a big problem.  Every Linux user I know has at least one partition for Windows or at the very least a virtual machine with Windows installed.  The downside to this would be relearning everything the C# way, and a lot of stuff that I have done is very specialized. I would have to relearn encryption, IO, everything.  But, that is needed anyway eventually.

Point of the day: Thank you microsoft for actually doing something right and offering a quick and easy way to impress myself and co-workers by creating Windows GUIs using WPF!

Gettings Started with WPF

It has been a very long time since I have taken any time to update this site.  About half a year ago, the webhoster account I had was somehow hacked and changed, so I basically had to start over completely fresh.  I have also been so busy with testing and stuff because my apprenticeship was over… no matter.  I have not really been taking care of this site for a long time due to a “rage quit” and life matters.

That being said, I just started a new phase where I am going to be getting to know a new way of programming user interfaces.  Up until now, I have been very swing oriented.  It just made sense, even if Java gui designs are not the most “up to date” or the coolest or the most windows OS oriented way of doing things.  For me in a time where I was new to programming it just made sense because everythings had its object and I used those objects and all was well.  It was consistant, fun, confusing, and messy.  I liked it.

Now, however, the time has come where I would like to expand my knowlege and get into the Microsoft C# way of doing things.  Basically, I found the following two ways to do things: Windows Forms, and Windows Presentation Foundation (WPF).  Of the two, WPF is newer and “more exciting”(?).

First off, coming from such a strict language as Java, C# feels like a loose language that does not fully respect the theory of OOP (object oriented programming).  And at first glance maybe it is possible to see it that way, but getting deeper into it, I must admit that it is not really so.  This, however, is not the point of this article.  I want to talk about WPF and Swing.

So lets jump into it and give a brief example of how I would design a main window in Swing.  First off, I take a piece of paper, draw out what I want, what should happen, what should be dynamic, what should be static, etc.  Then, with an understanding of what layout managers are available, I would draw out the different panels I need and mark out the best way to accomplish my mission with the different managers.  In the end, I always tend to use the same Layout Managers: GridBagLayout, BorderLayout, and every once in a while I’d put in a FlowLayout.  The GridLayout in my opinion was worthless, and a GridBagLayout took forever to set up and set up well, and then the code was nearly impossible to read afterward, not to mention that a complex layout could be multiple hundred lines of code.  Even I, who loves Swing and would most likely want to keep using it, have to admit that something like that is stupid.  This is one point where I would say that OOP is great, but there is no reason to be so into the philosophy behind it that I would want to have not only all of the controls, the layout manager and the panels, but also use a GridBagConstraints object to configure the whole thing.  It is just too complex and all of this is just because of a bit of philosophy.  So lets see how I think WPF makes this just a little better.

The user story is just about the same as Swing, I draw everything out on paper, mark up what I need, the highlighters run out of ink and I need to get some more from the corner store, come back, and before I know it I have a plan.  Well, good.  What do I do from there?  In WPF, Coding forms is “old school”.  Of course you can.  You can even, due to the “partial class” keyword, even go so far as to have all of the design in one document and all of the actions and stuff in another document.  No problem.  But that is still not the full power/annoyance/new stuff that WPF has to offer.

Instead of using C# code (that only “real” programmers will know) a form of eXtensible Markup Language (XML) is used to called XAML, eXtensible Application Markup Language.  Just the name is pretty cool.  It also has the advantage of being written by designers in a text file or other tool without a complex IDE.  When I look at a XAML document, I see all of the same sorts of definitions that I would expect to see in the code form of the window: labels, text boxes, column and row definitions, panels and layouts, but I see it in a well organized way without the confusing additions of code to select the right label, or code to set a dynamic color.  I just see what I need to see to understand the layout.  Then, when I look at the code for the Form or Window, I see the different functions that I need to make it look good.

Now, I am just starting out here, and I am not going to be able to say well how all of this works, but I do plan about writing about my process and hopefully get some good feedback.  I am going to, soon, write a short page on how to subscribe to this page in order to write comments, but for now please just write to me at my facebook page and I will get back to you.

Thanks for reading!