Quick and Easy: Move a Rectangle Using C# In a Windows Store App

My overall blog philosophy is that it’s perfectly fine to blog about old, settled subjects that have been covered to death elsewhere.  I assume this topic is one of those, but I’m blogging it anyway.

I’ve been working on a window store app and I’m at the part where I need to do some animating.  To this end, I’ve been figuring out bits and pieces of windows store app animation which, as it turns out, is quite close to, but not exactly like, XAML based animations in .NET (I’m still coming to grips with the fact that WinRT <> .NET 🙂 ).

This morning I wanted to get a handle on drag and drop operations.  En route to that, I got bogged down moving a rectangle instead :).  Here’s the code that moves a rectangle when the user clicks a button:

   1:   
   2:              MatrixTransform ct = (MatrixTransform)rectBig.RenderTransform;
   3:              Matrix m = ct.Matrix;
   4:              m.OffsetX += 10;
   5:              m.OffsetY += 10;
   6:              ct.Matrix = m;
   7:              rectBig.RenderTransform = ct;

The trick here is that I can’t directly change OffsetX or OffsetY.  There may be a more clever way of doing this (and if you know and feel like, please post in the comments). 

In order to do this, I need to:

1. Get the MatrixTransform of the rectangle (by casting RenderTransform).

2. Get the Matrix of that guy.

3. Change the Matrix’s offsets.

4. Reassign the Matrix back to the MatrixTransform.

5. Reassign the MatrixTransform back to the Rectangle.

To test it, I put a rectangle and button the screen. When I click the button, the above logic executes and moves the rectangle immediately.

At some point, I’d like to animate this but I have no idea how to get a DoubleAnimation to work on it (Storyboard.SetTargetProperty() is a mystery to me on this for the time being).

</end>

undefinedSubscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Setting the Height of ListboxItems In a ListBox Programmatically for Windows Store App

I’m working on a windows store application and one of the things I want to do in the app is display a log that shows status messages and other informational tidbits as the user works things.  To this end, I added a ListBox as follows:

<ListBox x:Name="GameStateLog" HorizontalAlignment="Center" Height="221" VerticalAlignment="Top" Width="499" Padding="0" FontSize="10">

 

The C# code to populate the listbox at runtime was along the lines of:

GameStateLog.Items.Insert(0, GameStateCounter++ + ": New game state: waiting for player 1 name");

This worked out fine enough but the UI showed a crazy amount of padding around the individual messages as they were added.  That makes sense if I want end users to be able to select these items but does not make sense when I just want to show a running series of log messages – users won’t select these, just view them.  It was strangely hard to find an easy way to do this and arguably, the way I found it isn’t necessarily “easy” but I got it working OK.  The key insight came from this posting here (http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c4a6f694-bd46-4779-ab83-b1c2fcb2397c) from Bob Relyea.  Instead of adding strings to the Items collection on the ListBox, add ListBoxItems.  By adding a string, the ListBox was creating its own ListBoxItem on its own.  I wasn’t able to affect anything about that ListBoxItem after the fact.  The new code is:

        private void AddGameStateLogMessage(string theMessage)
        {
            ListBoxItem li = new ListBoxItem();
            li.Content = theMessage;
            li.MaxHeight = 25;

            Thickness thisPadding = new Thickness(5, 0, 5, 0);
            li.Padding = thisPadding;

            GameStateLog.Items.Insert(0,li);
        }

 

Here I’m creating ListBoxItem’s and inserting them.  I removed the excess padding by setting its thickness.

This is pretty flexible as I do intend to do some color coding to highlight particular types of messages and by directly adding ListBoxItems I get to style them any way I want.

Hope this helps someone!

</end>

undefinedSubscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Quick and Easy – Safe Azure Queue Names

Silly but simple post.

As a follow-up to yesterday’s posting on “StorageException was unhandled” I thought I’d show the wee snippet of code I use to generate queue names:

 

        public static string GetRandomQueueName()
        {
            Guid g;
            g = System.Guid.NewGuid();
            return g.ToString();

        } 

Kind of silly in its simplicity but works well for me and has generated 100’s of safe queue names in the last couple of weeks.

</end>

undefinedSubscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Working with Azure Queues – “StorageException was unhandled”

I’ve been playing around with Azure queues for the last week or two and it’s been going smashingly.  Where were these things when I needed them back in 1990?

This article, in particular, is an excellent intro to queues for .NET programmers: http://www.windowsazure.com/en-us/develop/net/how-to-guides/queue-service/.  Using that article, I’ve been able to pull together a really nice bit of client-server logic that is so far reliable and just works with no grief.  Really – where was this stuff in 1990?

I did hit a small stumbling block right out of the gate, however.   As soon as I strayed from the specifics of the walk-through, I got hit with a StorageException and a “The remote server server returned an error (400) Bad Request.

image

It turned out that my queue name was off:

image

When I changed “OneQueueToRuleThemAll” to “onequeuetorulethemall” the StorageException went away.  I haven’t noticed any of the documentation calling this out but it may well do that.

Hope that helps someone.

</end>

undefinedSubscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Early Impressions on Surface Pro

[Update 3/26: I got a tweet from the @Surface people asking if they could help me with anything, so I made a plug for Swype, which they acknowledged with an “Interesting – Thanks for the feedback, Paul!”  I really think that Swype would make this device much easier to use for casual productivity.  (Also, fixed a typo pointed out to me by an old friend – thanks, Mike!)]

My office won a contest earlier this year with a small cash award attached to it.  I used the money to subsidize the purchase of a Surface Pro (128GB with the 2-year insurance plan) and I’ve been using a good deal since then.  I bought it from the Microsoft Store at the mall by Columbus Circle in Manhattan.  Total price was about $1300 USD with the better keyboard and the sucker’s insurance 🙂

I only got it 4 days ago and already I can hardly imagine not having it.  I brought to bed to read the so-far excellent Programming Windows 8 Apps with HTML, CSS, and JavaScript and it was the first thing I reached for when I woke up.

Here are some impressions, in no particular order:

How touching: I want to touch every screen I see now.

Windows 8 is for touch devices: I have a much stronger appreciation for Windows 8.  This O/S translates much better to a touch device than it does a keyboard.  At first, I didn’t know how to barely get started but it quickly became second nature for me. And it’s very fast and responsive, so you don’t feel like you’re lagging around or paying a penalty for a mistake.  I’m not an expert with the UI (mystery things still happen) but I’m flying all around the place with a good deal of confidence after a relatively small handful of hours on it

At the same time, now that I’ve been using touch, I have a much better understanding of the O/S from a Dell laptop perspective.  The mouse pad on my E6430 doesn’t compete with the Surface’s multiple points of contact, etc., but it does do a good job with some of the gestures.  But regardless of the mouse pad, having worked with the surface now, I know what’s happening when I move my mouse cursor around and various little cues pop up in the corners and such.

I also want to point out a line from this blog post by Brandon Carson:

Along comes Microsoft with a different perspective of how an operating system should support its users. Instead of two OS’s and a fragmentation between devices, Microsoft builds a new OS to blend the lean-back experience with the desktop experience and give the user control over how to interact with their device."

That line crystallized for me the whole point of Win8 as an O/S.  It’s an iPad and it’s laptop.  I like that.  I like that a lot.  I don’t bring my laptop to bed very often and when I do, it’s a novelty and a pain.  This thing can go everywhere with me, including work.

The windows store is awesome!  I just assumed, when I bought the Surface, that the windows app store would be a complete waste of time, a barren waste land of half-hearted apps clinging to the rocky soil, sad and pathetic.  I think that the various anti-Microsoft peoples are winning the hearts and minds argument here.  Although it’s empirically true that Apple and Google have bazillions more apps in their stores, dwarfing MSFT, MSFT still has a goodly selection and it’s growing.   My point isn’t that MSFT’s store is “better” than those, but that it’s not as bad as the intertubes will make you think.  Give it a look. There are many interesting apps out there.

Pen is awesome!: I have wanted the ability to write and sketch architecture diagrams FOREVER.  All the 3rd party things always felt kludgy unless you bought one that was expensive and I just didn’t feel like it.  With the surface, it’s totally natural and quick, plus lots of interesting apps available.  These include paint.net, something interesting from Evernote (Skitch), Onenote (which has first class support for the pen), PowerPoint (allows annotating and drawing during presentations).  I have barely scratched the surface here and I am loving it.  Check out this blog post for a more professional opinion on how Surface can be used for more industrial strength art.  I can’t wait for my next PPT demo.

It plays Civ5! (with a little help from some friends):  Civ with touch is really neat 🙂

Some annoyances:

  • Battery is not great.  No better than my laptop.  I have this vague notion that batteries need to be “conditioned” (but that’s probably nonsense) so if that’s the case, it may get better.
  • Keyboard is tiny.  But, I have been getting used to it.
  • No Swype! I just started using Swype a few months ago on my Galaxy S3 running Android and I can’t believe how productive it made me.  Not having that on Win8 is really frustrating and it seems like it will be a long time, if ever, before Swype is available.  Some other 3rd parties are working on it but my 30 seconds worth of research implies that the O/S jsut doesn’t support it.  (If you aren’t using Swype or one of its cousins you should stop reading this blog post and give it a try; this post will almost certainly still be here once you get back).
  • Overall form factor – still getting used to it.  It’s a beautiful screen and Netflix is great on it.  Web browsing is great on it. But, MS Word – kind of hard and not very touch friendly (to me, so far).  I’ve seen screen shots of people using visual studio on it – that seems like a stretch.  But I’m going to give it a try at some point.

So, there you go!  Hope this helps someone thinking about about it.  It’s too early for me to say “buy it!”.  I’ll revisit this post in a week or so and follow up.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

An Unexpectedly Awesome Team Building Exercise

I convened a team meeting here for the New York SharePoint team and at the last minute, for no particular reason, added a new agenda item:

Personal info exchange: I’m going to pull up google earth and each of us will tell the team where we were born and where we live today. I’ll map it real time. We’ll also do a quick rundown of our respective families. Feel free to create a fantasy family here but keep in mind that once you start lying about the family, you have to create successively elaborate lies and you will likely trip up at some point, so be prepared for that.

I thought this would take 20 minutes or so to do with nine people.  Instead, it took 90 minutes Smile, mainly because people spent significant amounts of time at different places around the globe.  It was a fascinating exercise and we surely learned a lot about each other.  I learned, finally, what people mean by “north” and “south” India.

If you can find the time in this busy and hectic days to do something like it, I heartily recommend it.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Tracking Practice Activities – Part 1

About a year ago, I joined Slalom Consulting here in new York as what we call a Practice Area Lead.  (As a minor aside to the point of this blog post, that change in jobs accounts for my total drop-off in blogging.  It was a big change in roles and a big change in day to day “stuff” but I’ve sort of acclimated myself to it and look forward to writing again Smile ).

In this PAL role, I’m responsible to save the company and the immediate environs of 21 West 21st street from disaster on a regular basis.  It’s a lot of pressure (more than you might think – just think of all the children!). 

In service to that imperative, I need to help out with pre-sales, create and update go-to-market offerings, hire good folks, train up folks to make them better (but really, to make my job easier) and occasionally do something billable at a client.  I get a lot of “input” – questions from clients, sales opportunities, my own addled thoughts and so forth.  Some of it’s really good (like a hot sales oppty) while a lot of it is less good.  The key is to initially track, prioritize and manage each of these ideas (great and small) to a successful conclusion. 

This kind of task management isn’t new, right?  And we have lots of task tools to help us with this.  Outlook has tasks.  You can slap a spreadsheet together nice and quick.  My very first task management tool was a legal notepad back in my days at GAF as a developer in the IT department.  (Ask me about those good old days the next time you see me if you’re interested, or maybe not…).

Being a SharePoint guy (nominally, at least), I’ve always thought to use SharePoint.  But for some reason, a generic Task list never quite did it for me.  A bunch of months ago, I decided to heal myself and just create a SharePoint based solution.  It was so embarrassingly easy to create that I thought to write about it here.

So, my goals here were very simple:

  • Super easy and fast data entry
  • Prioritize activities
  • Categorize activities
  • “next step” driven – these activities will often span weeks (maybe even months).  They almost never “end” after one specific update.

These bits lend themselves very nicely to a content type, so that’s what I created:

image

You can actually see that I had a sales bias with this at first, since I have that “Client” field.  A lot of my practice’s activities are based around clients (either actual or prospective).  But many of them are also internally focused.  I slap “Slalom” in there when I create them, but it always feels a tad weird.  I should have named it something more generic.  Maybe “Target Organization” or something.

Here are a few miscellaneous notes on the content type:

  • Activity Impact has devolved into a measurement of priority.  I’m not sure why I went with “Impact” and not “Priority” day zero, but that’s what I did. 
  • Next Steps and Next Steps Date – I have a dashboard that is driven by the next activity date.  This dashboard has sort of become my marching orders for the day/week.  I just go to the dashboard and focus on high priority stuff first and go from there.  (There’s the notion of an “untagged”
  • Primary Owner – the only thing of note is – isn’t it awesome that you can sort and filter on multi-select columns in SP 2010! I actually didn’t fully buy into this notion at first.
  • Activity Status – really just “Open” or “Closed.” 
  • Primary Practice – After I began using this, another PAL in my group wanted to try this out, so I slipped this into the mix to distinguish between my stuff (Portals & Collaboration) and her stuff (Azure).

Here’s my dashboard:

image

(sorry for all the blurred out bits – I didn’t feel like creating a bunch of test data and I don’t want to give anyone a heart attack over sharing vital details [see the bit in the intro re: save the world, etc., etc., etc.]).

I have several other views on this list, including a datasheet view that allows me to do mass updates.  I do this most often when a bunch of lower priority items I planned to do a never quite got done and need to be pushed out a week.

Every day, I pull up my activities log and just start working off the top of the list.

In part 2, I’ll explain how I made this even more useful with the addition of a nice email-enabled doc library and SPD workflow.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

Slalom Consulting–Boston SharePoint Leadership Needed

I joined Slalom consulting six months ago to the day and it’s been an incredible ride.  I plan to blog some more about that now that I am beginning to feel fairly solid.  Working here is like living in a fairy tale most of the time.  Smart people, interesting clients, solid support from management both local and corporate … the occasional libation … good stuff.

Our Boston office has just opened up and they are looking for a leader to launch their SharePoint practice.  It’s a very complex, full job with a lot of fun challenges.  You define offerings of interest to the local market, you roll up your sleeves and do real work and you hire folks to build up the best team you can manage.  I can’t recommend it strongly enough.

If you’re interested in this position or if you know anyone that might be interested, please fire off an email to me: paul.galvin@slalom.com.

I am glad to share my candid experiences (both good and bad) here in New York.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

My Workflow Book is Available to Purchase

I first started talking with my original co-authors over two years ago.  They eventually abandoned the project, but late this summer, with the help of several new co-authors, I was finally able to bring this across the finish line. 

Professional Workflow in SharePoint 2010: Real World Business Solutions hit Amazon and the Barnes and Noble web site some time in the last 10 days.  It’s available in paperback and Kindle/Nook and all of that, just in time for a great Christmas present. Smile

This book is about two things: 1) empowering end users so that they can solve their own business problems using SP 2010 workflow capabilities and 2) helping IT staff (developers in particular) do the same.  About two thirds of the book are targeted at what I call “Activist Users” (highly skilled but non-technical and motivated end users).  It tries to explain how to craft solutions in SharePoint 2010 using SharePoint Designer workflow and a number of additional SharePoint features.

The last third is aimed squarely at the developer.  However, unlike some of the purely technical books on the market, these chapters explain how SharePoint developers can create functionality that further empowers those activist users by means of custom SharePoint Designer activities and other technical bits.  By empowering the activist users in your organization, you free up your development team (or just yourself) to do the really hard (and typically more technically interesting) stuff that end users can never do and never should try on their own.

Over the coming weeks, I’ll write up more about the book, including fluffy stuff like “how is it like to write a book” that I know a lot of people are interested in knowing about.  First up – I’ll introduce my co-authors without whom this book would never have survived to see the light of day.

Read more about the book on the Amazon web site.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin

SharePoint Web Part UI Design Pattern Using XSL

I’ve been giving a talk this year on on a design pattern for SharePoint web parts where the UI is entirely managed via XSL. 

I plan to write this up in greater detail over the next period of time.  In the mean time, here is the PowerPoint.

The source code for this project is up on CodePlex here: http://webpartsxsl.codeplex.com/.

</end>

Subscribe to my blog.

Follow me on Twitter at http://www.twitter.com/pagalvin