Archive for category WPF
On August 6th Atlanta will be hosting ReMIX South 2011. There is going to be a lot of great topics covering some of the latest UI technologies such as HTML 5,Kinect and Mobile development. And for the UX types there will be some great content on UX techniques and how they can apply to these techs.
This is an exciting time for UI enthusiasts and this event will be a great place to come up to speed on the latest and greatest UI and UX concepts. So if you love UI then come on out, I hope to see you there!
So there has been a large demand for the code demos behind my videos so I am posting them up here.
I just added them to one big solution so if for some reason there are extra solution files or the code is in the final state of the videos its simply because I have just posted them however they were when I last touched them.
Thanks for all the great feedback on my videos and I hope you enjoy!
So after a long processing of getting my WPF training videos released they are finally out and available!
You can purchase them on InformIT here.
If you have a Safari account you already have access to them here.
I hope you enjoy the content provided and I definitely am looking for feedback!
I will be attending the South Florida Code Camp on February 12th 2011! I am going to be speaking on my asynchronous topic showing the different techniques we have used for asynchronous programming and how they evolved, and finally we will be looking at how Microsoft straightens out asynchronous programming with the new Visual Studio Async CTP. The samples revolve making asynchronous calls to WCF in WPF and Silverlight applications (which turns out to be one of the most common client uses for asynchronous programming).
For more information please visit http://www.fladotnet.com/codecamp/
I hope to see you there and have a good day!
I recently spoke at an MSDN geekSpeak on Asynchronous Programming techniques and how they have evolved over time. I wanted to give just the highlights of the different techniques and post the code. So here is a list of the different techniques I showed around making WCF calls in WPF and Silverlight asynchronously and some pros and cons about them!
- Event based – This technique was probably one of the first ways to write code that can be notified when an asynchronous process is complete. This technique helped in that it was a solution to the problem, but the code can be very disjointed and hard to read. Sometimes you only ever want to be notified through one chain of operations but with eventing it reads like it could happen multiple times
- Lambda Callbacks – Lambdas definitely helped to make the code more readable and took away the need for cleaner management of events. We still have certain ways we have to execute our operations and are never guaranteed that code will fire in order so we have to work around it. However this was a very big step towards making asynchronous coding more manageable and readable.
- WorkerQueue – A friend and co-worker of mine Nathan Allen wrote a tool that takes the idea of lambdas and really organizes the underlying processes to make it even easier to manage code. With the WorkerQueue you actually write synchronous code but you choose which lines you want to execute on a background thread versus lines you want to push to the ui thread and wait for them. This helps us to write synchronous code while still yielding the ui thread so we don’t lock up on longer running processes. You can get the code for this tool on his blog here.
- Visual Studio Async CTP (await/async) – With the new Visual Studio Async CTP Microsoft has really “straightened” out asynchronous programming by abstracting the complexity with threading and the like. With this new concept you truly write synchronous code without hardly any extra effort. In fact when you write code like this you can almost completely write in the way that synchronous code is written with a few extra keywords. Basically this implements some compiler sugar that for an async/await method creates a little mini state-machine. It will execute the lines until it hits an await then executes that on a Task, when the Task is completed it updates the state and executes the next step of the state machine. This is definitely my favorite technique next to using the WorkerQueue and I am eagerly awaiting the release of this extension.
I have posted the code samples here. You will probably need to install the Visual Studio Async CTP and you can get it and more information here. I don’t believe that this changes any core .net, just the compiler and visual studio.
I will be speaking on this topic at various events and will post each event I am speaking at on my blog. If you are in the area and would like to learn more about asynchronous programming then please come!
I hope you enjoy this and happy coding!
On January 12th 2011 at 3:00 PM EST, Glen Gordon Peter Laudati and I will be doing an MSDN geekSpeak event on Asynchronous programming techniques. We will cover a lot of different ways to write asynchronous code using the example of a smart client mentality (WPF or Silverlight) around WCF services.
While these techniques are not specific to calling WCF service and can be used for other mentalities like offloading long-running ui processes, this is a very common scenario for WPF and Silverlight applications and can help developers decide how to write their code. We will be covering Synchronous programming, Event Based programming, Lambda Callback based programming, Worker Queue based programming and finally the new Visual Studio Async CTP (await/async) programming style.
You can view the MSDN geekSpeak blog entry with more details and the registration link to sign up here.
I hope to see y’all there and happy coding!
It has been quite a while since my last blog post so its time for me to get back into the fray starting off with a couple of big announcements.
So my first big announcement is that I have a new job. Magenic is a great place and I am definitely sad to go, but an opportunity fell into my lap that I could not refuse. The name of the new company is called Veracity Solutions. I will technically be an independent sub-contractor working for my and my wife’s company Intuex., Inc.. Veracity works to find and sell projects and then partners with highly skilled independents to provide the development effort. A lot of the other consultants I have talked to have their own companies with multiple projects both from Veracity and their own efforts. I will get to work from home mostly which definitely makes me a very happy camper. There is also great potential for learning as I will join the ranks of some very very skilled individuals. I am hoping soon to get a website for our company Intuex sometime in the near future, so look for it!
WPF Training Videos
My second big announcement is that soon Sams Publishing will be releasing a set of WPF training videos through their LiveLessons brand. I have recorded 20 videos spanning about 7-7.5 hours ranging from basic introduction to key WPF concepts to some of the more advanced topics like Custom Controls, Localization, Navigation and of course MVVM. I am hoping to get the videos for final author review this week and I have marked them as complete after possibly some tweaks it’ll just be a short time before they are released. I believe that they will be released on Safari so if you already have an account you can easily get to these videos. I believe they will also be sold on InformIT but I am not 100% sure of this.
So look forward to these videos and I definitely welcome feedback and criticism on them!
Another thing I have going on in my head is to start working on Razre 2. Back a year ago I had wanted to build a WPF Application Framework that provided out of the box a lot of stuff that helps out when building WPF applications, not just another MVVM framework, but also providing many many more things to help with like navigation, themes and some other useful tools. Well I had my initial release and then got very busy so I never came back to it. A lot has changed since then and there are a few things I would now do differently so I think I am going to start over with Razre 2.
I intend Razre 2 to be compatible with not just WPF but also Silverlight and hopefully a mobile version for Windows Phone 7. I have a lot of ideas on what I want this framework to support but I have to get them all wrapped around in my head. Whether or not I actually get started on this project is another story but i would definitely consider bringing in others that would be interested in working on a project like this. Lets hope this gets off the ground and look forward to seeing the results!
C# Optional Parameters and Generic constraints
So since I haven’t posted in a while I figured I would include something technical. I would like to share this nifty little piece of information I figured out about C# optional parameters when combined with generic constraints.
So first I want you to just look at the code sample below; do you think it would compile?
public void SomeMethod<T>(T something = null)
where T : ISomething
if (something == null)
The correct answer is that no it will not compile. This is the error you get if you try to compile this.
A value of type ‘<null>’ cannot be used as a default parameter because there are no standard conversions to type ‘T’
So basically what I am guessing is that it cannot determine if T is nullable based on all possible incoming types constrained to the interface. What’s weird though is that the IF statement right below it compiles just fine. Based on the constrained interface the IF statement will allow a null check but the optional parameter doesn’t? That’s a little strange if you ask me.
Fortunately if you need something like this there is a solution! All you have to do is change T something = null to T something = default(T) as such.
public void SomeMethod<T>(T something = default(T))
where T : ISomething
if (something == null)
So now this tells the compiler to resolve the default of T which in almost every case will resolve to null. The only time this may not happen is if you have a struct that implements this interface, otherwise you know its a normal object type so you can do a null check.
By using default(T) this allows us to have optional parameters in C# that are constrained to an interface which to me is pretty useful in some cases.
Well I am hoping to be back to being more active on my blog and some other community events now that the big things like my training videos and this new job are over. I hope you enjoy this and have a great day!
I have a few sessions submitted to CodeStock 2010 this year! These sessions are on the multi-touch and Silverlight 4 Validation topics I have been looking into recently. If you enjoyed the blogs and want more detail and guidance on the topics please vote for my sessions!
You can find them at
Thanks again and have a good day!
We had a great time at the Columbia Code Camp this year. A lot of great speakers and volunteers to help with the event. We had I think around 150 people show up which was amazing since it was snowing, raining and freezing temperatures .
I did my multi-touch presentation for the first time and I think it went very well. Had some great feedback and questions afterwards.
So as promised I am posting up the materials and a quick explanation of what is available to use for Multi-Touch in WPF and Silverlight. In the demo code for WPF you will need to change the App.xaml to point to the different demo windows. You can download the demo code here.
In both WPF and Silverlight there is a concept called Raw Touch. These events are close to the mouse events in that they work with a device and a point (position) on the visual. Here are the events:
- TouchDown – Occurs when a touch device touches the visual
- TouchMove – Occurs when a touch device is down and starts to move across the visual
- TouchUp – Occurs when the touch device is lifted off the visual
- TouchEnter – Occurs when the touch device is down and while moving enters a new visual
- TouchLeave – Occurs when the touch device is down and while moving leaves a visual
- Touch.TouchFrameReported – Static Event that is fired any time a touch device activates on a visual
In WPF we can attach handlers to the above events to an individual element and they will only fire when touch is activated on that visual. For Silverlight however we do not have this. The TouchFrameReported event will fire no matter what visual has had touch activated. It is constantly looking for this event on a frame draw. Even if you touch your finger down and hold it without moving the TouchFrameReported event is still firing with a Move action.
The key to these events (even the Silverlight one) is the GetTouchPoint or GetTouchPoints methods. With these methods you can pass in an element and get the point that you are currently touching. What’s cool about this is that if we have 2 elements one of top of the other, but the element underneath is larger than the we actually touched, we can pass in the element underneath and get the touch point relative to that element instead of the one on top. So we have a lot of power behind where we can get these touch points in relation to which elements we have defined.
Another key to RawTouch is the Device’s Device Id. Each unique finger that touches the screen will get a unique device ID. By utilizing this device ID we can accurately keep track of which finger is performing what action and act appropriately. By doing this we can now truly write something in Multi-Touch .
To see more detail please look at the RawTouch and Gesture demos. The Gesture demos show how we can write one common library in WPF and Silverlight that can recognize straight line gesture activations and abstractly report them to a handler or command.
One other cool thing that we do have in WPF that we don’t have in Silverlight is Manipulations. These events take alot of the guess work out of raw touch and simplifies the data passed into the handlers.
The events to take note of are:
- ManipulationStarting – occurs when a manipulation is triggered and about to start
- ManipulationStarted – occurs when a manipulation has started
- ManipulationDelta – occurs when a manipulation has changed its data based on movement
- ManipulationInertiaStarting – occurs when inertia is about to kick in for a manipulation.
Lets say we want to handle the pinching resize functionality that seems to be common in multi-touch. Well with RawTouch that would be very difficult as we have to calculate that 2 touch points are moving in opposite directions away from each other. Then we have to calculate the difference between them and provide a scale vector. This could be a real pain to do in RawTouch.
With Manipulations all of that hard work is done for us. When the ManipulationDelta event fires the args provide a DeltaManipulation with a Scale property. This Scale is the vector difference of our resize. If Scale is not populated then we know we did not do a resize. We are also provided with a Rotate that is a decimal in the degree change and a Translate which handles straight movement. Manipulations make it very easy to get started with multi-touch.
Inertia is a cool way to provide smooth deceleration transitions from a manipulation to a stopping point. Lets say you move a rectangle across the screen but you don’t want it to stop immediately when you lift your finger, but instead you want it to keep going and slow down to a stopping point. Inertia is an easy way to allow this.
When the ManipulationInertiaStarting event fires it has already calculated your velocity for you! It has determined how much distance was crossed and how fast your manipulation occured to give you this initial velocity. From this you just provide it a deceleration rate to tell it how fast it needs to slow down. A deceleration rate of 10 inches per second every second could look like this “10.0 * 96 / (1000 * 1000)”. With this we can control how it slows down when continuing a manipulation.
For more detail on the code please see the demos provided.
Well thats the basics of what multi-touch capabilities are provided in WPF and Silverlight. I hope you enjoyed this topic and enjoy the code!
I will be presenting on this topic in Atlanta at the Atlanta MS Pros user group on March 1st. I hope to see you there!
Its been a bit since my last blog post, so I thought i would give an update as to what I have been working on.
On January 30th I will be travelling to Columbia, SC to speak at the Columbia CodeCamp! I have been working hard on a new presentation that will cover the popular topic of Touch and Multi-Touch.
In this presentation I will be going over the different ways Touch and Multi-Touch can be handled in WPF and Silverlight. It will show things like Raw Touch, Manipulations and Gestures in both of these technologies. I have about 7 demo’s already coded to show the different ways of accomplishing this as well as a sample on how to build a fully abstracted gesture processor where there is a common code base for both WPF and Silverlight, and it actually works!
After I present this for the first time at the Columbia CodeCamp I will be shortly blogging about it and posting the source code. After that I plan on speaking on this topic somewhere in Atlanta TBD.
If you are in the area for the code camp please drop by, its free, alot of fun and there will be lots to learn. You can register for the code camp at http://columbiacodecamp.com.
Hope to see your there!