Design-Time Support for WinRT

Topics: Conventions
Oct 28, 2013 at 3:58 PM
I have tried to enable the Caliburn.Micro inside the Visual Studio designer (or Blend) on WinRT by following the documentation.

Here are my test code:
public class MainViewModel
    public MainViewModel()
        Title = Execute.InDesignMode.ToString();
    public string Title { get; set; }
    d:DataContext="{d:DesignInstance Type=local:MainViewModel, IsDesignTimeCreatable=True}"

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock FontSize="42" x:Name="Title"/>
The issue is that it doesn't work unless I add Text="{Binding Title} into TextBlock. And if I added it, the TextBlock shows "False" which means the Execute.InDesignMode is false. Is this the expected behavior (i.e., Convention is not supposed to work in design mode)?
Oct 29, 2013 at 3:11 AM
I look into the Caliburn.Micro source code and I think the PlatformProvider.Current is always set to DefaultPlatformProvider (which always returns false IsDesignMode). In other platforms, it should get replaced by XamlPlatformProvider, but WinRT doesn't use Bootstrapper, so it never happens.

My work around right now is to add the following code at the beginning of Bind.AtDesignTimeChanged:
#if WinRT
            if (Windows.ApplicationModel.DesignMode.DesignModeEnabled
                && PlatformProvider.Current is DefaultPlatformProvider)
                PlatformProvider.Current = new XamlPlatformProvider();
This way, XamlPlatformProvider is used when the Bind.AtDesignTime is set in XAML.

Please let me know if you have any comment.
Oct 29, 2013 at 5:45 AM
This should be fixed in latest commit.
Oct 29, 2013 at 6:23 PM
Edited Oct 30, 2013 at 4:45 AM
I spoke it too soon. I re-test again, and the design-time binding still doesn't work as expected. Are Bootstrapper.Start() and CaliburnApplication.Initialize() get called in design time?
Oct 30, 2013 at 8:23 PM
You are right, it does not work for WinRT ;-(
I created an issue

Your workaround is a nice idea, but it does not execute the StartDesignTime() logic that is needed too.
For me this seems to be a bigger problem than initially thought.
Oct 30, 2013 at 9:07 PM
I agree that this seems to be a bigger issue. My workaround is more like a hack to fix the issue, so I am ok with it for now.

The Design-Time support does work with the current version on NuGet (1.5.2) though.

If I found more information, I will add my comment to the issue.

Thanks all Caliburn.Micro developers for this very nice framework!