Navigation

Monday, August 23, 2010

How to implement TextWrapping in a Silverlight AutoCompleteBox

The Silverlight AutoCompleteBox control is a great control, however, there are some properties that it does not expose like TextWrapping that you might need to access.

The AutoCompleteBox inherits from the TextBox control so accessing the underlying controls properties will allow you to do so.

Simple create a new class file like below which inherits the AutoCompleteBox and on the loaded event gets a reference to the underlying TextBox by calling the GetTemplateChild function of the class.  The GetTempleteChild returns the named element in the visual tree of an instantiated ControlTemplete.  Then simply set the value of the TextBox property.

Public Class clsMyTextBox
    Inherits AutoCompleteBox
    Private _text As TextBox

    Private Sub clsMyTextBox_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        _text = GetTemplateChild("Text")
        _text.TextWrapping = System.Windows.TextWrapping.Wrap

    End Sub
End Class

Some lesser-known truths about programming

Some lesser-known truths about programming
by Dot MacAdventures with OS X and DotNet


My experience as a programmer has taught me a few things about writing software. Here are some things that people might find surprising about writing code:


•A programmer spends about 10-20% of his time writing code, and most programmers write about 10-12 lines of code per day that goes into the final product, regardless of their skill level. Good programmers spend much of the other 90% thinking, researching, and experimenting to find the best design. Bad programmers spend much of that 90% debugging code by randomly making changes and seeing if they work.

“A great lathe operator commands several times the wage of an average lathe operator, but a great writer of software code is worth 10,000 times the price of an average software writer.” –Bill Gates

•A good programmer is ten times more productive than an average programmer. A great programmer is 20-100 times more productive than the average. This is not an exaggeration – studies since the 1960′s have consistently shown this. A bad programmer is not just unproductive – he will not only not get any work done, but create a lot of work and headaches for others to fix.

•Great programmers spend very little of their time writing code – at least code that ends up in the final product. Programmers who spend much of their time writing code are too lazy, too ignorant, or too arrogant to find existing solutions to old problems. Great programmers are masters at recognizing and reusing common patterns. Good programmers are not afraid to refactor (rewrite) their code constantly to reach the ideal design. Bad programmers write code which lacks conceptual integrity, non-redundancy, hierarchy, and patterns, and so is very difficult to refactor. It’s easier to throw away bad code and start over than to change it.

•Software obeys the laws of entropy, like everything else. Continuous change leads to software rot, which erodes the conceptual integrity of the original design. Software rot is unavoidable, but programmers who fail to take conceptual integrity into consideration create software that rots so so fast that it becomes worthless before it is even completed. Entropic failure of conceptual integrity is probably the most common reason for software project failure. (The second most common reason is delivering something other than what the customer wanted.) Software rot slows down progress exponentially, so many projects face exploding timelines and budgets before they are killed.

•A 2004 study found that most software projects (51%) will fail in a critical aspect, and 15% will fail totally. This is an improvement since 1994, when 31% failed.

•Although most software is made by teams, it is not a democratic activity. Usually, just one person is responsible for the design, and the rest of the team fills in the details.

•Programming is hard work. It’s an intense mental activity. Good programmers think about their work 24/7. They write their most important code in the shower and in their dreams. Because the most important work is done away from a keyboard, software projects cannot be accelerated by spending more time in the office or adding more people to a project.

Friday, August 20, 2010

VS2010 Toolbox Search

Have you ever wanted to be able to search the VS2010 toolbox for the control your looking for?  Well you can!

The visual studio team has added the ability to search for controls in the toolbox by name.  To use it, put focus in the toolbox (by clicking in it, for example) and then start typing the name of the control you want to find.  As you type, the selection will move to the next item that matches what you've typed so far.  The text you've typed is shown in the status bar, like this:
You can hit Backspace if you mistyped a character, or Tab to go to the next match for the current string.  To cancel the search, you can hit Escape, move the selection, or click on another window.

You can also collapse all the groups by pressing "/" (and you can expand them all with "*")

What is the Open Data Protocol (oData)?

I have been getting alot of questions about what oData is so this post is intended to provide a little detail on the topic.

The Open Data Protocol (OData) is an open protocol for sharing data. It provides a way to break down data silos and increase the shared value of data by creating an ecosystem in which data consumers can interoperate with data producers in a way that is far more powerful than currently possible, enabling more applications to make sense of a broader set of data. Every producer and consumer of data that participates in this ecosystem increases its overall value.

Data has become a first-class element of the web. The Open Data Protocol (OData) applies web technologies such as HTTP, AtomPub and JSON to enable a wide range of data sources to be exposed on the web in a simple, secure and interoperable way. Whether you have a simple collection of reference data, are building a Rich Internet Application or are building the web API for your web property, the Open Data Protocol enables you to expose your data and its associated logic as an OData feed. Once your data is available as an OData feed it can be consumed by any of the available OData-aware developer libraries/tools, business intelligence products, visualization components, etc.

The Open Data Protocol specification is currently available under the Microsoft Open Specification Promise (OSP), allowing third parties, including open source projects, to build Data Services for any runtime as well as clients to consume such services.

Here are some good links on the topic;

http://www.odata.org/
http://msdn.microsoft.com/en-us/data/ee844254.aspx
http://alexbarnett.net/blog/archive/2010/03/19/why-odata-matters-imho.aspx
www.silverlight.net/content/samples/odataexplorer
http://www.hanselman.com/blog/CreatingAnODataAPIForStackOverflowIncludingXMLAndJSONIn30Minutes.aspx

Debugging Tips with Visual Studio 2010

This is a great article from Scott Guthrie on Debugging Tips!

Debugging Tips with Visual Studio 2010

This is the twenty-sixth in a series of blog posts I’m doing on the VS 2010 and .NET 4 release.

Today’s blog post covers some useful debugging tips that you can use with Visual Studio.  My friend Scott Cate (who has blogged dozens of great VS tips and tricks here) recently highlighted these to me as good tips that most developers using Visual Studio don’t seem to know about (even though most have been in the product for awhile).  Hopefully this post will help you discover them if you aren’t already taking advantage of them.  They are all easy to learn, and can help save you a bunch of time.

Run to Cursor (Ctrl + F10)

Often I see people debugging applications by hitting a breakpoint early in their application, and then repeatedly using F10/F11 to step through their code until they reach the actual location they really want to investigate.  In some cases they are carefully observing each statement they step over along the way (in which case using F10/F11 makes sense).  Often, though, people are just trying to quickly advance to the line of code they really care about – in which case using F10/F11 isn’t the best way to do this.

Instead, you might want to take advantage of the “run to cursor” feature that the debugger supports.  Simply position your cursor on the line in your code that you want to run the application to, and then press the Ctrl + F10 keys together.  This will run the application to that line location and then break into the debugger – saving you from having to make multiple F10/F11 keystrokes to get there.  This works even if the line of code you want to run to is in a separate method or class from the one you are currently debugging.

Conditional Breakpoints

Another common thing we often see in usability studies are cases where developers set breakpoints, run the application, try out some input, hit a breakpoint, and manually check if some condition is true before deciding to investigate further.  If the scenario doesn’t match what they are after, they press F5 to continue the app, try out some other input, and repeat the process manually.

Visual Studio’s conditional breakpoint capability provides a much, much easier way to handle this. Conditional breakpoints allow you to break in the debugger only if some specific condition that you specify is met.  They help you avoid having to manually inspect/resume your application, and can make the whole debugging process a lot less manual and tedious.

How to Enable a Conditional Breakpoint

Setting up a conditional breakpoint is really easy.  Press F9 in your code to set a breakpoint on a particular line:

image

Then right-click on the breakpoint “red circle” on the left of the editor and select the “Condition…” context menu:

image

This will bring up a dialog that allows you indicate that the breakpoint should only be hit if some condition is true.  For example, we could indicate that we only want to break in the debugger if the size of the local paginatedDinners list is less than 10 by writing the code expression below:

image

Now when I re-run the application and do a search, the debugger will only break if I perform a search that returns less than 10 dinners.  If there are more than 10 dinners then the breakpoint won’t be hit.

Hit Count Feature

Sometimes you only want to break on a condition the Nth time it is true.  For example: only break the 5th time less than 10 dinners is returned from a search.

You can enable this by right-clicking on a breakpoint and selecting the “Hit count…” menu command.

image

This will bring up a dialog that allows you to indicate that the breakpoint will only be hit the Nth time a condition is met, or every N times it is met, or every time after N occurrences:

image

Machine/Thread/Process Filtering

You can also right-click on a breakpoint and select the “Filter..” menu command to indicate that a breakpoint should only be hit if it occurs on a specific machine, or in a specific process, or on a specific thread.

TracePoints – Custom Actions When Hitting a BreakPoint

A debugging feature that a lot of people don’t know about is the ability to use TracePoints.  A TracePoint is a breakpoint that has some custom action that triggers when the breakpoint is hit.  This feature is particularly useful when you want to observe behavior within your application without breaking into the debugger.

I’m going to use a simple Console application to demonstrate how we might be able to take advantage of TracePoints.  Below is a recursive implementation of the Fibonacci sequence:

image

In the application above, we are using Console.WriteLine() to output the final Fibonacci sequence value for a specific input.  What if we wanted to observe the Fibonacci recursive sequence in action along the way within the debugger – without actually pausing the execution of it?  TracePoints can help us easily do this.

Setting up a TracePoint

You can enable a TracePoint by using F9 to set a breakpoint on a line of code, and then right-click on the breakpoint and choose the “When Hit…” context menu command:

image

This will bring up the following dialog – which allows you to specify what should happen when the breakpoint is hit:

image

Above we’ve specified that we want to print a trace message anytime the breakpoint condition is met.  Notice that we’ve specified that we want to output the value of the local variable “x” as part of the message.  Local variables can be referenced using the {variableName} syntax.  There are also built-in commands (like $CALLER, $CALLSTACK, $FUNCTION, etc) that can be used to output common values within your trace messages.

Above we’ve also checked the “continue execution” checkbox at the bottom – which indicates that we do not want the application to break in the debugger.  Instead it will continue running – with the only difference being that our custom trace message will be output each time the breakpoint condition is met. 

And now when we run the application, we’ll find that our custom trace messages automatically show up in the “output” window of Visual Studio – allowing us to follow the recursive behavior of the application:

image

You can alternatively wire-up a custom trace listener to your application - in which case the messages you print from your TracePoints will be piped to it instead of the VS output window.

TracePoints – Running a Custom Macro

In a talk I gave last week in London, someone in the audience asked whether it was possible to automatically output all of the local variables when a TracePoint was hit. 

This capability isn’t built-in to Visual Studio – but can be enabled by writing a custom Macro in Visual Studio, and then wiring up a TracePoint to call the Macro when it is hit.  To enable this, open up the Macros IDE within Visual Studio (Tools->Macros->Macros IDE menu command).  Then under the MyMacros node in the project explorer, select a module or create a new one (for example: add one named “UsefulThings”).  Then paste the following VB macro code into the module and save it:

Sub DumpLocals()

Dim outputWindow As EnvDTE.OutputWindow

        outputWindow = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput).Object

Dim currentStackFrame As EnvDTE.StackFrame

        currentStackFrame = DTE.Debugger.CurrentStackFrame

        outputWindow.ActivePane.OutputString("*Dumping Local Variables*" + vbCrLf)

For Each exp As EnvDTE.Expression In currentStackFrame.Locals

            outputWindow.ActivePane.OutputString(exp.Name + " = " + exp.Value.ToString() + vbCrLf)

Next

End Sub

The above macro code loops through the current stack frame and dumps all local variables to the output window.

Using our custom DumpLocals Custom Macro

We can then take advantage of our custom “DumpLocals” macro using the simple addition application below:

image

We’ll use F9 to set a breakpoint on the return statement within our “Add” method above.  We’ll then right-click on the breakpoint and select the “When hit” menu command:

image

This will bring up the following dialog.  Unlike before where we used the “Print a message” checkbox option and manually specified the variables we wanted to output, this time we’ll instead select the “Run a macro” checkbox and point to the custom UsefulThings.DumpLocals macro we created above:

image

We’ll keep the “continue execution” checkbox selected so that the program will continue running even when our TracePoints are hit.

Running the Application

And now when we press F5 and run the application, we’ll see the following output show up in the Visual Studio “output” window when our Add method is invoked.  Note how the macro is automatically listing the name and value of each local variable when the TracePoint is hit:

image

Summary

The Visual Studio debugger is incredibly rich.  I highly recommend setting aside some time to really learn all of its features.  The above tips and tricks are but a few of the many features it provides that most people are actually unaware of.

I’ve previously blogged about other VS 2010 Debugger Improvements (including DataTip pinning, Import/Export of Breakpoints, Preserving Last Value Variables, and more).  I’ll be doing more blog posts in the future about the new VS 2010 Intellitrace and Dump File Debugging support as well.  These provide a bunch of additional cool new capabilities that can make debugging applications (including ones in production) a lot easier and more powerful.

Also make sure to check out Scott Cate’s excellent Visual Studio 2010 Tips and Tricks series to learn more about how to best take advantage of Visual Studio.  He has an absolutely awesome set of free videos and blog posts.

And also check out Jim Griesmer’s great series on Visual Studio Debugging Trips and Tricks.  He has a ton of good tips and tricks you can take advantage of.

A Guided Tour of Microsoft Visual Studio 2010 Database Development

This is a good article on the database design features of VS2010.
http://jpda.me/aRA2WQ

Monday, August 16, 2010

Free Online Course Authoring Tool from Microsoft Learning LCDS 2.5!

The Microsoft Learning Content Development System (LCDS) is a free tool that enables the Microsoft Learning community to create high-quality, interactive, online courses. The LCDS allows anyone in the Microsoft Learning community to publish e-learning courses by completing the easy-to-use LCDS forms that seamlessly generate highly customized content, interactive activities, quizzes, games, assessments, animations, demos, and other multimedia.

http://jpda.me/aiZnNw

Thursday, August 12, 2010

Visual Studio 2010 Bug; "Insufficient avaiable memory to meet the expected demands..." on cut and paste!

If you’re getting the error below on cut-n-paste operations there is a patch for it.  You can download the patch from Microsoft's visual studio blog website at http://jpda.me/9bRy9v.

"Microsoft Visual Studio" "Insufficient available memory to meet the expected demands of an operation at this time, possibly due to virtual address space fragmentation. Please try again later."

Visual Studio 2010 and .NET Framework 4 Training Kit

The Visual Studio 2010 and .NET Framework 4 Training Kit is a great resource for developers.  It included alot of example code on various parts of the framework (data access, wcf, wpf, WF).

http://jpda.me/bB0cle

Monday, August 09, 2010

Tuesday, August 03, 2010

Countdown to PDC2010!

Microsoft's Channel9 has a short video on the upcomming PDC at MSFT HQ in October.
Countdown to PDC: Developers, Developers, Developers
http://bit.ly/9jHKix

Microsoft Visual Studio LightSwitch Comming Soon!

Microsoft today announced Visual Studio LightSwitch (previously codenamed Kitty Hawk), the newest member of the Visual Studio product family. It will be available as part of Visual Studio Professional, Premium, and Ultimate. Microsoft says that LightSwitch is aimed at developers of all skill levels and organizational sizes who want to build business applications that target the desktop, cloud, and Web.


A beta will be available on August 23 to MSDN Subscribers, with general availability to follow, and the software giant is hoping to get feedback as it works on getting a final version released by next year.

Visual Studio LightSwitch includes pre-built templates and tools in a simplified development environment for building scalable custom business applications that connect with existing applications, legacy systems, and Web services. Developers can choose from a wide variety of hosting, deployment, and third-party plug-in options. Deployment is simplified in that applications (which are at their core Silverlight applications) can be deployed to the client, browser, and even Windows Azure (post-beta). LightSwitch can be used with C# or Visual Basic and it supports SQL Server, SQL Azure, SharePoint, and Microsoft Office.

Microsoft says that LightSwitch dramatically decreases the time it takes to build a custom application by automatically handling routine code; it's a rapid application development tool that offers application shells and screen templates to allow the developer to concentrate on the core business logic.

There's also a lot of "drag and drop" functionality, but full access to the .NET Framework is still available; if you need to tinker under the hood, you can do so by opening your LightSwitch application in the "full" version of Visual Studio.

How does LightSwitch compare to Microsoft's recently announced WebMatrix Web development suite? Both are tools for building applications, but the approach and target audience is very different: WebMatrix is HTML UI and LightSwitch is Silverlight UI.

WebMatrix is a tool that includes a Web server (IIS Developer Express), a simple database (SQL Server Compact), and programming framework (ASP.NET). It is targeted at non-professional developers to make it easier to create new websites from scratch, or use Microsoft's Web Application Gallery to customize popular ASP.NET and PHP open source community applications. In contrast, LightSwitch is targeted at professional developers and power users looking to create custom Line of Business (LOB) applications using data from multiple sources.

Microsoft Website for Visual Studio LightSwitch
http://jpda.me/9ecRmA

Jason Zanders Weblog Article on Lightswitch
http://jpda.me/9dd0jN

Somasegars Weblog article on Lightswitch
http://jpda.me/dgNnLU

Timesnapper!

I have been using this for the last few days and really love it.
http://www.timesnapper.com/

Monday, August 02, 2010

Channel9 video about how we are integrating IIS Express (and SQL CE and Razor syntax) with VS 2010

http://bit.ly/dCcPQc

Productivity Power Tools Update Released

Another update to this great VS add-in!

http://blogs.msdn.com/b/visualstudio/archive/2010/07/28/fixes-for-solution-navigator-amp-quick-access-in-the-productivity-power-tools.aspx

Principles of Software Development (aka Principles of Shipping)

Microsoft's Ivo Manolov's latest article in his "Principles series" about software development.
http://jpda.me/bbs6ak

Principles of Software Testing

This is another great article from Microsofts Ivo Manalov in his "Principles Series".
http://jpda.me/ayLkI8

Corning's Gorilla Glass Heading for the Bigtime!

In 1962 Corning developed a super strong and lightweight glass that has sat unused for that last 40+ years.  However, cell phone and TV manufactures, looking for ways to provide strong and light protective screens for there products have discovered this might be the right solution.

Take a look at this interseting article on the subject.
http://jpda.me/azvDQW

History of corning;
http://jpda.me/bA85hG

Goes to show that R&D keeps paying of for years so invest in it!