Design-Time Support for WinRT

Topics: Conventions
Oct 28, 2013 at 2:58 PM
Hi,
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; }
}
<Page
    x:Class="CaliburnMicroDesignTimeTest.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:CaliburnMicroDesignTimeTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:micro="using:Caliburn.Micro"
    mc:Ignorable="d"
    d:DataContext="{d:DesignInstance Type=local:MainViewModel, IsDesignTimeCreatable=True}"
    micro:Bind.AtDesignTime="True">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <TextBlock FontSize="42" x:Name="Title"/>
    </Grid>
</Page>
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 2: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();
            }
#endif
This way, XamlPlatformProvider is used when the Bind.AtDesignTime is set in XAML.

Please let me know if you have any comment.
Thanks,
--karlkim
Oct 29, 2013 at 4:45 AM
This should be fixed in latest commit.
Oct 29, 2013 at 5:23 PM
Edited Oct 30, 2013 at 3: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 7:23 PM
You are right, it does not work for WinRT ;-(
I created an issue https://caliburnmicro.codeplex.com/workitem/344

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 8: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!