Update: How to enable Google Gears in Mozilla Prism

In the current version of Gears you can enable the extension with the trick i posted here, but the applications failes to load Gears. Thanks to gera0ul which pointed out how to make it work.

The problem turns out to be the detection code in components/stub.js in the xpi.
Before creating the zip/xpi, if I change the function getLibFilename in
components/stub.js to return “ff30”, and *then* install the xpi in Prism, it works.

So all you need to do is to grab the Gears xpi file and let the getLibFilename function in components/stub.js directly in line 1 return “ff30” if you use Firefox 3.0 or return “ff35” if you use Firefox 3.5. And now you can install the xpi as any other Firefox extension. But it is important to edit the file before you install the extension, because otherwise it dose not work.

This is a hack, but since the issue is in the Gears bugtracker and it it set to accepted, we can hope that it will get fixed in the near future.


CommandProxy: Howto databind a ICommand to an InputBinding

When you start using the ViewModel pattern in WPF, some day you stumble upon that it is not possible to databind an command to an MouseBinding or KeyBinding.

So why this is not possible?

The WPF DataBinding’s are heavily based on DependencyPropertys which are only work on objects which inherit from DependencyObject. But the Command property on Mouse- and KeyBinding isnt an DependencyProperty. So DataBinding will not work on them.

The next problem is that the InputBinding class is only derived from DependencyObject and so it has no inheritance context which allow to get access to DataContext and ElementName.

May it is a performance consideration, may it is mistake, finally i dont know why they make this decision.

So how to make the DataBinding work anyway?

My solution is called CommandProxy and it uses a simpified version of Josh Smith Virtual Branch technic.

So here the CommandProxy looks like:

    public class CommandProxy : Freezable, ICommand
    {
        protected override Freezable CreateInstanceCore()
        {
            return new CommandProxy();
        }

        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.Register( "Command",
                typeof(ICommand),
                typeof(CommandProxy),
                new UIPropertyMetadata() );

        public ICommand Command
        {
            get { return (ICommand)GetValue( CommandProperty ); }
            set { SetValue( CommandProperty, value ); }
        }

        public void Execute( object parameter )
        {
            Command.Execute( parameter );
        }

        public bool CanExecute( object parameter )
        {
            return Command != null && Command.CanExecute( parameter );
        }

        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    }

And here is how to use it:

    <Grid Background="LightGreen">

        <Grid.Resources>

            <a:CommandProxy x:Key="TestCommand"
                    Command="{Binding TestCommand}" />

        </Grid.Resources>

        <Grid.InputBindings>

            <MouseBinding Command="{StaticResource TestCommand}" Gesture="LeftClick" />

        </Grid.InputBindings>

        <TextBlock Text="click here" VerticalAlignment="Center" TextAlignment="Center" />

    </Grid>

As the name suggests, all this class dose is to expose a ICommand interface and redirect its methods to the databound command. The inheritance context problem is resolve by inherting from Freezable. You can read more about why Freezable helps here, in Dr. WPFs Blog here.

Download the CommandProxySample Visual Studio 2008 Solution.

How to prevent FireFox from storing Main Window size and location on close

As a two monitor user, i want Firefox to always open and maximized on the second monitor. The problem is that by default Fixfox saves the location, size and window mode to the Localstore.rdf file in the profile directory on each window close. And so if you need to move one window to the first monitor and close it there. Firefox now always opens new window on the first monitor.

Since i dont found any configuration option to do this, ive searched on the Firefox extensibility points and found a solution.

In Firefox all is html (not really, this is called XUL) also the main window. So if you go to chrome://browser/content/browser.xul, you can inspect the dom of the Firefox main window with Firebug as you can do it with any web page.

If you look at the root element you can see an persit attribute with the values ‘screenX screenY width height sizemode’. As this looks very promising,ive tryed to set this attribute to ” and this did it!

I am not an Firefox extension developer, but ive collected enouth informations to create an simple extension which simply sets the persit attribute to ” while the window load event. Ive called it “Dont Store Main-Window Size and Location” and you can download it below.

Download donststoremainwindowsizeandlocation@lanwin.de_1.0.0.xpi

First steps to allow precompilation to NHaml

Currently i made some tests on my private branch. The problem with this is that there is no way to get the model type and the view – layout combinition before the controller was executed.

So what i did to solve this. Ive added a new markup to NHaml with name MetaMarkupRule. This markup is implemented as property bag and this property’s are passed to the parser at compile time instead of runtime.

The idea is the following: In the view Ive put the a line like this (i currently don’t know if ~ is the best char for this):

~model=System.String
%p
foo

Which results in a model property with value System.String which is passed to the Meta Dictionary inside of the TemplateParser.

The next step is to put a generic base type to the TemplateCompiler like this typeof(MyCustomView<>). Then direct after the parse step and right before the compiler melts the source and compiles it, we read the value of the model property if it is available (otherwise the default is System.Object) and create the model type with MakeGenericType of the base type. The result then looks like MyCustomView<System.String> which is this what you currently get if you call return View(“myview”,”mycustommodelstring”).

This could be the way to go for precompilation. After the precompilation return View(“myview”,”mycustommodelstring”) would not longer create the type, instead it searches in the list of the precompiled views and raises an exception if it dose not found the matching view type.

To solve the view-layout combinition problem we simply compile a version auf each view/layout combination that exists or we allow the view to specify also the layout. It is also an idea to allow a view specifiy more then one model. This could work as long as the both model types have the same propertys which are used in the view on it.

Alternativ content propertys in Expression Blend

Look at the Header
Look at the <>Header

Did you ever noticed that there a way in expression blend to directly edit a second content property of a element which is not the default content and without using a resource? Yep, look at the “<> Header”, there could be placed the second content.

WPF per default provides some of this controls. In example MenuItem,HeaderedContentControl,BulletDecorator … So ive started to find out how to create such a property by myself. After some time of searching ive saw only the way to use Reflector to figure out why Expression Blend exposes this properts.

And the answer is not nice. The hardcoded this behavior into Blend for every control which exposes such a property.

I couldnt belive it, there must be a common way to do it, so ive decided to write a feature request to Microsoft Connect for exposing a common way to expose such a property from my custom code (my first report to Microsoft Connect).

And here is it: https://connect.microsoft.com/Expression/feedback/ViewFeedback.aspx?FeedbackID=411558

My expectation was that this would be a long time open, but it was not. It was closed at the same day ive reported it and with the information i want to hear 🙂

Thanks for the feedback- in the next version of Expression Blend we will be adding a new attribute which will allow additional content properties on controls’ Look for ‘AlternateContentPropertyAttribute’ in the next version of the extensibility APIs.

I am looking forward to the next Blend release.

Update: Here is a link how this feature look like in the next Blend version.

Layout tables torn me away

As i read this post i was torn away of it.

No i am not a fan of layout tables and my overall goal is it to avoid them where it is possible. But i think the real problem is not that layout tables are bad (they are) rather that you need a lot more time to archive the same result in CSS as you need with layout tables. And there are a lot of pain on the way if you not have the wisdom of all the CSS hacks you need to be done.

For me as someone who loves clean html it is often very hard because i dose not often have the chance to work on web applications.

But i am looking forward to the new Internet Explorrer 8 which hopefulle will smoth down the entry fight and made the work with CSS less painfull.

Sidenote – I nerve believed to here this from Microsoft:

We also believe IE8 RC1 has the most complete implementation of the CSS 2.1 specification in the industry.

You can read the entry story and this post if the IE Team Blog.

The NHaml way to prevent presentation concerns in controllers

Based on Ayende’s post about not putting presentation concerns in the controller, here is the NHaml way of setting the page title in the view.

ViewsShareApplication.haml:

^ var title = “Page”;
!!!
%html{xmlns=”http://www.w3.org/1999/xhtml”}
%head
%title = title
%body
_

ViewsHomeIndex.haml;

– title = “Home Page”;
%content
This is my Home Page

ViewsHomeAbout.haml;

– title = “About Page”;
%content
This is my About Page

Simple isnt it?

I am a team member of the NHaml project

Haml project logo

In fact i am joined for a while now, but i blog about it first now. You take the question what is NHaml? NHaml is a .Net port of the excellent Ruby Haml which is a HTML/Xml DSL ported by Andrew Peters which also provides a ASP.Net ViewEngine.  You could read more on his blog.

I really like the simplicity and cleanness templates of haml and i see a lot potential there, so my first step was to refactor NHaml to allow alternative TemplateCompiles instead of C#. While i dose this, ill added a Boo TemplateCompiler and Andrew later a IronRuby Template compiler. Since a few days now boo has also a Sample MVC Application which demonstrates how it work.

But there is a lot of more work to do, i added some of my ideas to the bugtracker of NHaml and hope to get all done. The next major steps are to provide all Haml 2.0 language features like filters and alligators. For later i also plan to add an working MonoRail ViewEngine.

Update:
Sergio Pereira hase made a nice overview of the benefits NHaml can give us.

Howto enable Google Gears in Mozilla Prism

Update: Here is an post how to get it to work with the lasted Gears.

Mozilla Prism is a Add-On for Firefox or a standalone application with enable you to use web applications like Remember The Milk or Google Reader as desktop application. For this types of application it make sence to have offline support from Google Gears. But Google Gears dose not support Prism yet. With this post i will discribe how to enable although.

First you need to allow Prism to load the addon.

Open “C:program filesGoogleGoogle GearsFirefoxinstall.rdf” and insert the following code directly under the last </em:targetApplication> tag.

<!-- Prism -->
<em:targetApplication>
<Description>
<em:id>prism@developer.mozilla.org</em:id>
<em:minVersion>0.8</em:minVersion>
<em:maxVersion>1.0.0.*</em:maxVersion>
</Description>
</em:targetApplication>

Save the file and go to your windows profile directory. For vista this is “C:Users{username}”. Then enbale windows to show all hidden and system files. From there go to “AppDataRoamingPrism{Application name}Profiles{random chars}.defaultextensions”. The {} parts are different on any system and must be replaced by you.

In example for a Remember The Milk application on windows vista this is:

"C:UsersBill GatesAppDataRoamingPrismRemember The MilkProfiles123abcd.defaultextensions"

In this folder you now simply create a text file where you place only the path to the Google Gears Firefox extension in. It seems the the file name is unimportant.

In example for me the file is named “google_gears” and it contains “C:Program FilesGoogleGoogle GearsFirefox”.

That should it be, but on my system i only works if i installed a second extenions direct aside.

For this you could use in allready installed firefox extension (in example Stylish). Simply go to your firefox profile extension folder and copy the folder of your extension to the same folder where you place the “google_gears” file.