Posts tagged Silverlight

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 a calculator. [...]

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.