Colin Eberhardt has posted a neat multi-purpose value converter that tries various conventional conversion methods to convert from one type to another. This overcomes a frustrating limitation in WPF/Silverlight data binding where the XAML parser is seemingly more intelligent at converting literal values to target types than values sourced from binding expressions. Unfortunately, the TypeConverter [...]
Posts tagged Silverlight
Windows 7 Style "Aero" ChildWindow Template
Silverlight 3 introduced a very useful control called a ChildWindow. This is a “modal” dialog box that can contain whatever content you give it and it floats above the rest of the application inside a Popup control. I say “modal” because unlike ShowDialog in WPF or Windows Forms, showing a ChildWindow via the Show method returns immediately, but it does disable the application’s RootVisual which prevents the user from interacting with the rest of the application while the window is showing.
As cool as this control is, I have always been pretty disappointed in the default behavior and look and feel of the ChildWindow class. For example, the animation as it opens and closes is very unnatural and distracting. The overlay that “dims” the rest of the application successfully indicates the modal nature of the control, but it’s too strong I think. In fact I’m fine with just the normal “grey out” that happens when the RootVisual is disabled.
A while back I had created a pretty lame ChildWindow template that kinda sorta looked like a Windows 7 Aero window. It was a half-hearted attempt but it looked a lot better than the above. But then I saw a question on StackOverflow asking about creating an Aero glass style window and I decided to revisit the problem and try to come up with something decent.
SwitchConverter – A "switch statement" for XAML
Download the example project which includes the source for SwitchConverter and SwitchedContent. I figured I would write some more about value converters since I think there’s a lot of cool things you can do with them, especially when you put a little extra effort into generalizing them. One thing I find I need to do [...]
A multi-purpose NegateConverter for WPF/Silverlight
I came across a question on StackOverflow that is a very frequently asked question regarding data binding in XAML. Given a boolean, how do you bind the opposite value to the target? The answer of course is to use a value converter (a class implementing IValueConverter) and invert the boolean in code. I do this [...]
Lost “Button” Simulator in Silverlight
To celebrate the upcoming finale of LOST, I threw this thing together in Silverlight 4 using Expression Blend 4 and Visual Studio 2010. I also used a trial of Goldwave 5 to work on the sound effects. I’ve included the source code so you can take a look around. This is an example of a [...]
Tip for adding Silverlight references in Blend
I find it very frustrating sometimes to get something to build in Blend. Like many developers, I have a "Me.dll" that contains a lot of commonly used classes, custom controls, etc. As you might expect, this DLL often takes dependencies on other DLL’s that must also then be referenced. In Blend, this can be a [...]
Accept simple mathematical expressions in Silverlight text boxes
Download MathEvalConverter.zip Background With the name Einstein, people typically assume I’m good at math. I have the utmost respect for the physicists and mathemeticians of our time, prior, and beyond. But to be honest, math is not my strong suit. In fact I have great difficulty simply adding or subtracting numbers without the use of [...]
Silverlight: Animated "Turbo Tax" style number display
If you’ve used Turbo Tax, you may have noticed the prominent “Federal Refund” box that’s ever-present at the top of the page while you’re figuring out your taxes. I like this UI concept because when most people are filing their taxes, there’s only one number they actually care about and they care about it every step of the way.
One nice little touch about the display is that whenever you make changes to your return that affect the federal refund, instead of the field just changing immediately, it has a nice incrementing (or decrementing if you’re like me) animation. It is a subtle effect that draws your attention to the field whenever it changes. Try the working example below.
Recently I worked on a line of business application that would benefit from a similar UI. The application is for pricing out sales proposals and takes into account cost of goods, retail price, agent commission, etc. At every step of the way, slight changes to the various inputs affect the bottom line which is the profitability of the deal. So the profitability is always displayed on the screen. When the value changes, I wanted to have this smooth animation between numbers just like Turbo Tax. Turns out it isn’t that hard.
Mouse Wheel Behavior for Silverlight 3
As you may know, Silverlight 2 did not support the mouse wheel natively. You needed to hook into the HTML bridge and access the mouse wheel events from the DOM, hit test the control that it intersected, then act on the mouse wheel data. Silverlight 3 still does not implement the mouse wheel for scrolling by default, but it does expose a MouseWheel event on UIElement that eliminates the need to hook the events in the DOM.
One caveat though is that the MouseWheel event only fires under Internet Explorer or out-of-browser applications. For other browsers and operating systems, you will still need to use the DOM’s mouse wheel events.
So anyway, I wrapped up the mouse wheel code in a “behavior” that you can just drop onto any element that contains a ScrollViewer element (multi-line textbox, list box, etc.) and it implements vertical scrolling with no code.
Source code is attached below.
Posts