1

Blend 4では、VMクラスからサンプルデータソースを生成しようとしています。このクラスには、インターフェイスのobservablecollectionを返すプロパティと、クラスのobservablecollectionを持つ別のプロパティがあります。サンプルデータソースを生成する場合、Blendはクラスプロパティのデータを生成しますが、インターフェイスは生成しません。これを回避する方法はありますか?私のコードには絶対にインターフェースが必要ですが、同時に、設計時に生成されたサンプルデータを確認できるようにしたいと思います。

4

1 に答える 1

2

ここでの問題は、BlendがIDataInterfaceの具体的な実装として作成するオブジェクトの種類を認識していないことです。MyVM用と具体的なIDataInterface実装用の2つの設計時データソースを作成することをお勧めします。

namespace SilverlightApplication1
{
    public interface IDataInterface 
    { 
        string Stuff { get; set; } 
    }

    public class PartialViewModel<M> 
    { 
        public M Model { get; private set; } 
    }

    public class ConcreteDataInterface : IDataInterface
    {
        public ConcreteDataInterface()
        {
            this.Stuff = "Concrete Stuff!";
        }

        public string Stuff {get;set;}
    }

    public class MyVM 
    { 
        public PartialViewModel<IDataInterface> Partial 
        { 
            get; 
            private set; 
        } 
    }
}

XAMLは次のようになります。

<UserControl x:Class="SilverlightApplication1.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot"
        d:DataContext="{d:DesignData /SampleData/MyVMSampleData.xaml}">
      <Grid DataContext="{Binding Partial.Model}" 
            d:DataContext="{d:DesignData /SampleData/ConcreteDataInterfaceSampleData.xaml}">
          <TextBlock Text="{Binding Stuff}"/>
      </Grid>
    </Grid>
</UserControl>
于 2011-04-05T15:59:42.443 に答える