NumericTextBoxBehavior for XAML-based Windows Store Applications

One of the first (and arguably most useful) behaviors that I wrote for MVVMHelpers was a NumericTextBoxBehavior.  This is a WPF behavior that restricts the input for a TextBox to be numeric-only.  Recently, someone emailed me asking if it was possible to do the same thing in a Windows Store application.  It absolutely is, but there are some caveats. My original implementation for WPF utilizes preview events - these are events which are sent to the ancestors of the element prior to it receiving a … [Read more...]

Default and Cancel button behaviors

One of the things I miss from WPF moving to Windows Store Apps is the ability to define a "Cancel" and "Default" button.  These are buttons which are automatically invoked when you press ENTER or ESC.  A prompt from a fellow developer got me to thinking about how we could accomplish this with an attached behavior until Microsoft decides to add the support into the framework.  Here's the usage I wanted:   A few rules: It should not invoke the default or cancel buttons if they … [Read more...]

Managing focus with MVVM in Windows Store Apps

One thing that is always troublesome in MVVM is focus-management. How can we push focus to a specific control during business logic processing and still keep a clean separation of UI and logic? There are likely several good solutions out there, but one I have used in the past is a Blend Behavior called SetFocusAction. I ported this behavior to the 8.1 Windows Store model (and it also exists in 8.0 as part of my full behaviors package with MVVMHelpers). Using it is pretty easy - let's pretend we … [Read more...]

Behaviors in Windows 8.1 Store Apps

Visual Studio 2013 RC was released to MSDN this week and it includes some very cool new features which have been detailed on various blogs around the Internet.  One feature I've not seen much coverage of, but am very excited about is support for Blend behaviors.  If you create a new Windows Store application using the 8.1 profile you will find Blend behaviors in the Assets tab: The list of behaviors is small - compared to WPF and Silverlight, but all the important ones are there, along with a … [Read more...]

Making Async Popups in WSAs

The async and await keywords are awesome and allow for a much easier style of async programming over the traditional callback approach. Ideally, we could use these everywhere in our programming - particularly for UI environments such as Window Store apps. But not all the APIs are programmed this way in WinRT - take for example the Popup control. You show the Popup by setting the IsOpen property to "true" and then close it by resetting it to "false". This is a holdover from the WPF/SL world … [Read more...]

Using .NET Bio with Windows Store apps

We recently published .NET Bio 1.1 (see bio.codeplex.com) and included a version for Mono in the source tree which allows you to use C# and .NET Bio but run the applications on Linux or Mac machines when Windows just isn't available.  You can even use Xamarin Studio to build the apps which is quite cool.  [Check out the Bio.Mono solution in the source code on codeplex for that project!] Lately, I've spent a lot of time in Windows Store land building Windows Store apps - so I thought I'd try to … [Read more...]

Adding a watermark to a PasswordBox in a Windows Store app

In the previous post, I wrote about a Blend behavior for Windows Store apps to add a watermark to a TextBox.  The next question I got was "Well, what about a PasswordBox?" PasswordBox is a bit tricker since it doesn't allow text to be displayed in the clear - so our little trick of changing the Text property doesn't work here.  So, instead, let's get a little hacky (or clever depending on how you look at it I suppose).  We can use the same series of events (GotFocus/LostFocus/Loaded) but instead … [Read more...]

Watermark TextBox in Windows Store apps

A common request for WSAs is to add a "watermark" to TextBox entries so users get a hint as to what is expected in the TextBox. You can see this in many Search Charm implementations as it allows a search hint to be provided via the SearchPane.PlaceHolderText property.  However, the built-in TextBox in XAML doesn't have this feature (HTML does!). There are a few custom controls out there which allow for this, however, I'm a big fan of behaviors over custom controls - so when I needed this, I … [Read more...]

Variable sized tiles in Windows Store Apps

One of the common requests I hear when training customers on Windows 8 is "How do I create variable sized tiles in a GridView?" The Windows Store app utilize this technique where different tiles have different sizes to promote content. It turns out this is relatively easy in HTML - which is probably one of the reasons Microsoft chose to use that visual platform to build the app.  In XAML however, this is a bit more difficult.  There are many posts which detail using a VariableSizeWrapGrid … [Read more...]