Extensions Made Easy: dispatcher fixed & IsEnabled feature.

Dispatcher fixed

In case you haven’t tried it, Extensions Made Easy includes a really easy way to add commands to the button ribbon.  By default, the code you want executed will run on the dispatcher of the currently active screen, if there is one, or on the main dispatcher if there is no currently active screen.

However, the former sometimes poses a problem.  For certain pieces of code, you want to be on the main thread because you are going to access global resources for example.  For this reason, you might sometimes want to force your command’s code to run on the main thread, and this can now be done since Extensions Made Easy v1.6, thanks to an overloaded constructor in the ExtensionsMadeEasy.ClientAPI.Commands.EasyCommandExporter…

This piece of code will execute on the dispatcher of the currently active screen:

public DynamicThemeCommand()
 : base(
   "Edit theme", //Display name
   "Edit the current theme", //Description
   "Customize", //Ribbon button group name
   null //URI to image (was too lazy today to actually include one)
 ) { }

And this is the second constructor, where you can force the main dispatcher…

public DynamicThemeCommand()
 : base(
   "Edit theme", //Display name
   "Edit the current theme", //Description
   "Customize", //Ribbon button group name
   null, //URI to image (was too lazy today)
 ) { }

And yes, that command IS a command from the EME 2.0 series which I’m currently working on


New IsEnabled feature

About a month ago, a comment from Bala, volunteer to be my partner in crime from now on, slipped under my radar:

I was playing with this again and got stuck on how to ‘disable a global button’, something like “CanExecute” validation.
Is it possible to implement?

I found the comment by accident – yes I’ve been terrible with following up my comments… will do better next year! – when trying to find another comment for my previous post

Now, it was already fairly easy to indicate whether or not your command should be active (visible) for a particular screen.

        public override bool IsCommandActiveForScreen(Microsoft.LightSwitch.Client.IScreenObject currentScreen)
            return currentScreen != null; //3.

But as Bala indicated, sometimes a command should be visible, but disabled based on the situation.  Extensions Made Easy v1.8 just got pushed to the gallery, including a new property on the ExtensionsMadeEasy.ClientAPI.Commands.EasyCommandExporter called IsEnabled.

public override void Execute(Microsoft.LightSwitch.Client.IScreenObject currentScreen)
   new ExtensionsMadeEasy.Presentation.Themes.DynamicControl.Views.DynamicThemeManagementView().Show(currentScreen, null);
   this.IsEnabled = false;

Set it to true of false whenever you feel like it, the property properly raises the INotifyChanged event and the LightSwitch framework immediately disables or enables the command.


Aight, out of ammunition for this blog post (V, 2 ,2!  Extra credit for anyone to know where V, 2, 2 comes from…), moving on to write the EME change log, another long overdue item on my TODO pile…

11 thoughts on “Extensions Made Easy: dispatcher fixed & IsEnabled feature.

  1. Thanks for this IsEnabled update Jan. I’ll test it sometime this week and post my update here.

    Besides other than Theme & Shell, can we export control extension into EME? We talked abt “Screen Template” a while ago and you mentioned that “Screen” is design time render rather than runtime.

    Does the same applicable to Controls too? Currently debugging custom control extensions are pain, if you ask me.

    • Hey Bala!
      The reason I haven’t moved on to Control Extensions is because they have custom “properties” that can be set in the UI. An “EasyControl” would not have the same integration with the UI, however we could overcome this by allowing the developer to pass his custom properties with the “EasyControlExporter”… Other than that, I see no reason why this wouldn’t work, let’s implement it together and see how far we get?
      Let us know how the IsEnabled update works out for you!
      Keep rocking!

  2. If there is one using EME extensively after you, that may be me, I guess. It wouldn’t be fair to use it without rate.

    I tried to use Nuget to push my two extensions that I published in MSDN, but couldn’t get it through. Didn’t want to disturb u at this stage. I’ll keep digging it.

    Happy new year Jan. 🙂

  3. Hi Jan, Wish you a very happy new year! 🙂 And hope you rock this year with LightSwitch posts. 🙂

    No,, actually.. I don’t even know what I’m doing with NuGet. Can I use NuGet for any type of extensions, or just Theme/Shell extension?

    And “when you get time”, could you please write-up a step-by-step tutorial post for newbies like me?

    • Hey Bala,
      I’m sure Nuget could do a lot of really usefull stuff for LS, but at the moment I only investigated the Theme&Shell extensions, because those are the only ones currently supported in EME.
      That “step-by-step” tutorial is something I planned for a couple of months ago, long overdue meanwhile, but not yet forgotten.
      Keep rocking LS my friend, I must admit that your recent work (blog & extensions) are interesting & valuable to all of us!
      We have a good year ahead 🙂

  4. Pingback: Extensions Made Easy: UseSmallImage and custom ordering. « Jan Van der Haegen's blog

  5. Pingback: Windows Azure and Cloud Computing Posts for 1/18/2012+ - Windows Azure Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s