Mvvm 在blend中使用F#ViewModel作为设计实例

Mvvm 在blend中使用F#ViewModel作为设计实例,mvvm,f#,blend,design-time-data,Mvvm,F#,Blend,Design Time Data,我有一些在F#中创建的viewmodels,希望将它们用于Blend中的设计时数据,但我不知道如何使其工作 我有一个简单的xaml文件,其中包含一些绑定设置,如下所示: <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="usi

我有一些在F#中创建的viewmodels,希望将它们用于Blend中的设计时数据,但我不知道如何使其工作

我有一个简单的xaml文件,其中包含一些绑定设置,如下所示:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:RacePacesUI"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Class="RacePacesUI.RacePaceEntryControl"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400"
    xmlns:SampleData="using:RacePacesUI.SampleData"
    d:DataContext="{d:DesignInstance Type=SampleData:EntrySampleVm, d:IsDesignTimeCreatable=True}">
  public class EntrySampleVm : ViewModels.EntryVm
  {
    public EntrySampleVm()
    {
      Distance = 26.2;
      Time = new TimeSpan(3, 30, 25);
      Pace = 4.0;
      Speed = 16.5;
    }
  }
  public class Test 
  {
    public Test()
    {
      Distance = 26.2;
      Time = new TimeSpan(3, 30, 25);
      Pace = 4.0;
      Speed = 16.5;
    }

    public TimeSpan Time { get; set; }
    public double Distance { get; set; }
    public double Pace { get; set; }
    public double Speed { get; set; }
  }
d:DataContext="{d:DesignInstance Type=SampleData:Test, d:IsDesignTimeCreatable=True}">
ViewModels.EntryVm是我的F#ViewModel类

很遗憾,我在设计器中遇到一个错误:

EntrySampleVm does not exist in this namespace
我在同一命名空间中定义了一个类似的C#类,如下所示:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:RacePacesUI"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Class="RacePacesUI.RacePaceEntryControl"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400"
    xmlns:SampleData="using:RacePacesUI.SampleData"
    d:DataContext="{d:DesignInstance Type=SampleData:EntrySampleVm, d:IsDesignTimeCreatable=True}">
  public class EntrySampleVm : ViewModels.EntryVm
  {
    public EntrySampleVm()
    {
      Distance = 26.2;
      Time = new TimeSpan(3, 30, 25);
      Pace = 4.0;
      Speed = 16.5;
    }
  }
  public class Test 
  {
    public Test()
    {
      Distance = 26.2;
      Time = new TimeSpan(3, 30, 25);
      Pace = 4.0;
      Speed = 16.5;
    }

    public TimeSpan Time { get; set; }
    public double Distance { get; set; }
    public double Pace { get; set; }
    public double Speed { get; set; }
  }
d:DataContext="{d:DesignInstance Type=SampleData:Test, d:IsDesignTimeCreatable=True}">
如果我随后设置DataContext,如下所示:

<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:RacePacesUI"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Class="RacePacesUI.RacePaceEntryControl"
    mc:Ignorable="d"
    d:DesignHeight="300"
    d:DesignWidth="400"
    xmlns:SampleData="using:RacePacesUI.SampleData"
    d:DataContext="{d:DesignInstance Type=SampleData:EntrySampleVm, d:IsDesignTimeCreatable=True}">
  public class EntrySampleVm : ViewModels.EntryVm
  {
    public EntrySampleVm()
    {
      Distance = 26.2;
      Time = new TimeSpan(3, 30, 25);
      Pace = 4.0;
      Speed = 16.5;
    }
  }
  public class Test 
  {
    public Test()
    {
      Distance = 26.2;
      Time = new TimeSpan(3, 30, 25);
      Pace = 4.0;
      Speed = 16.5;
    }

    public TimeSpan Time { get; set; }
    public double Distance { get; set; }
    public double Pace { get; set; }
    public double Speed { get; set; }
  }
d:DataContext="{d:DesignInstance Type=SampleData:Test, d:IsDesignTimeCreatable=True}">
然后一切都按预期进行,因此使用F#ViewModel绝对是如此

有没有办法让它发挥作用? 我真的不喜欢ServiceLocator方法,因为我正在创建一个Windows Phone项目,所以我没有访问x:Static和x:Type扩展的权限

我正在使用Blend版本:12.0.51020.0更新4 VS2013:12.0.31101.00更新4

谢谢你的帮助