Pages

Showing posts with label Silverlight. Show all posts
Showing posts with label Silverlight. Show all posts

Saturday, September 15, 2012

SelfNote: SilverLight GetRoot


To get the current window, should use Window.GetWindow(currentElement) and then find Visual, not the Application.Current.RootVisual.

private static void SetRootVisual()
{
    if ((_rootVisual == null) && (Application.Current != null))
    {
        _rootVisual = Application.Current.RootVisual as FrameworkElement;
        if (_rootVisual != null)
        {
            _rootVisual.MouseMove += new MouseEventHandler(ToolTipService.OnRootMouseMove);
            _rootVisual.SizeChanged += new SizeChangedEventHandler(ToolTipService.OnRootVisualSizeChanged);
        }
    }
}

Monday, October 10, 2011

F# doing WP7 app - More Silverlight


All WP7 by F# can be found at:


Listed below:
  • Earthquake Alert

The earthquake alert notifies you the unusual shake occurred on the surface where the phone is put on. Put the phone on a still flat surface and press start in the next page to start the application. The screen lock will be disabled, so your phone will use more power than usual. Connect the phone charger if you plan to leave the application open for long time, for example, when sleeping. The screen lock will be reactivated once the application is closed. Please Use the phone’s volume control to adjust the alert sound volume to your preferred level.

This application is not a replacement of professional devices. Please always contact your local authority to verify.



  • Expert Sudoku
This game is for those truly into Sudoku, an addictive and challenging game that will drive you mad but keep you itching for more.  Expert Sudoku provides over 6000 expert level puzzles.All games are true Sudoku, with a single solution that can be discovered by logic alone. If you doubt that a Sudoku puzzle can be solved by logic, simply have the hint system show it to you step by step. Come enjoy the rich feature set and advanced hint system. The more you play, the more of a Sudoku expert you will be!

Features include:

- Over 6000 free Sudoku puzzles 
- Optimized for fewer touches
- Undo/redo
- Large, high contrast digits are easy to read
- Ability to delete all pencil marks and/or reset puzzle
- Hint system to provide advice once you're stuck.  
- Ability to check all pencil marks with one key stroke
- Save partially solved games
- Load games 
- Enable user to choose if to show suggestion and highlight
- Save current game as a picture

  • Level
 two tools in one: a level and it also show the current the gravity unit and record the gravity. The level also provides the lean angle and measure angles by using saved angle feature.



F# doing WP7 app - Silverlight-based


All WP7 by F# can be found at:



This is the free version of the widely beloved WP7 game "Love Dice".

Looking for naughty ways to spice up your love life? Look no further. Get the good times rolling and break the ice with these Love dices. After a few rolls, you're guaranteed to get lucky. There are no losers in this game!

One dice describes a body part: Lips, Ears, Neck, Toes, Chest, your choice … by default 12 different body parts. The other dice describes an action: Lick, Tickle, Rub, Kiss, Massage, Surprise … by default 11 different actions. You are free to remove any items and add your own action/body parts. You can lock one dice and roll the other. Be creative!

To be played by two or more adults. Take turns rolling the dice and explore each other's intimate side. Let the games begin...

Sunday, October 2, 2011

Install F# for Silverlight 4.0 runtime

The machine configuration is always a painful process unless it works as installation package promises. Today the Silverlight4_Tools.exe drives me nuts when I try to install F# for Silverlight 4 runtime. No matter how many times you run that EXE file, SL4 just won't be picked up by F#!

Here is a way to verify the SL is actually installed:
  1. go to C:\Program Files (x86)\Microsoft F#\Silverlight\Libraries\Client
  2. make sure there is a folder called 4.0 created
In order to make sure the folder is actually created by the installer, follow steps listed below:
  1. download the "Microsoft Silverlight 4 Tools for Visual Studio 2010", do not run it
  2. extract files using WinRAR
  3. find "FSharpRuntimeSL4.msi" in the extract folder
  4. run the "FSharpRuntimeSL4.msi"

Tuesday, September 6, 2011

WPF/SilverLight F# Converter

Since 2006 I started to develop WPF application, I experienced the pain of writing XAML, binding, converter, coerce, and the MVVM pattern. I find the F# is the best tool to write converters. I can still recall somebody was trying to write some framework to chain some multiple converters. I published a snippet on http://fssnip.net/7Q.

First of all, let me justify converter is still useful when MVVM pattern is available. First application of converter is for graphic designers. The converter provide graphic designer some basic mathematically tool to design a control. The MVVM pattern is too much for a graphic designer. Secondly, the MVVM itself can use converter as well. The last point is how big is your project. I would not say MVVM pattern is suitable for a small demo project. Use the right tool at the right time to do the right job is the key.

The converter snippet design idea is simple. It groups the functions into a module and function composition and pipeline can chain different function and form a new function. The converter basically is a function, you can use strategy pattern (http://fssnip.net/7k) as the starting point to design a converter.

The hard part is how to make your function look like (object, type, object, cultureInfo) format. The following function is the function to convert your function to (object, type, object,cultureInfo) signature.


let convert<'T> f (obj:System.Object) (t:Type) (para:System.Object) (culture:Globalization.CultureInfo)  = (obj :?> 'T) |> f |> box
The concrete implementation is to chain up different function to form a string to visibility as convert function and nullFunction as convertBack function. The converter is trying to reduce the coding effort and make sure the generated code can work with Blend. I added another converter which I used a lot in my data binding debugging. The converter itself does not do anything, but can be used to check if the binding actually work or not.

Thursday, October 7, 2010

Load data template in Silverlight 4

load a data template in Silverlight is painful job. You can always get some error like: The element is already a child of an element [line 0: position 0].

Please do not forget to add your library as the namespace and your assembly, even though your control is in the same assembly.

var template = (DataTemplate)XamlReader.Load(String.Format(@"xmlns:SilverlightControlLibrary=""clr-namespace:SilverlightControlLibrary;assembly=MyAssembly""> ", i++));