我正在使用MVVMLight运行wpf应用程序并尝试启用设计时数据。
public EngineerViewModel(IEngineer engineerService, IProject projectSevice, IBirdsEye birdsEyeService, ISampleData sampleData)
{
if (IsInDesignMode)
{
var graph = new ObservableCollection<GraphSample>()
{
new GraphSample()
{
StandardHours = 75,
WeekNo = 1
},
new GraphSample()
{
StandardHours = 70,
WeekNo = 2
},
};
SampleGraph = graph;
}
else
{
_engineerService = engineerService;
_projectService = projectSevice;
_birdsEyeService = birdsEyeService;
_sampleService = sampleData;
ComShowProject = new RelayCommand(() => ShowProjectDetails());
LoadProjectsForEngineer();
SampleGraph = _sampleService.GetSampleGraph();
}
}
private ObservableCollection<GraphSample> _sampleGraph;
public ObservableCollection<GraphSample> SampleGraph
{
get { return _sampleGraph; }
set { _sampleGraph = value; RaisePropertyChanged("SampleGraph"); }
}
<dxc:BarSideBySideSeries2D DataSource="{Binding SampleGraph,UpdateSourceTrigger=PropertyChanged}" d:DataContext="{Binding SampleGraph,UpdateSourceTrigger=PropertyChanged}"
ArgumentDataMember="WeekNo" ValueDataMember="StandardHours" Brush="#FFC54F4F" ShowInLegend="True" LabelsVisibility="True" />
数据显示在运行时但不在设计中。 任何明显的我都会失踪。 非常感谢 斯科特
答案 0 :(得分:1)
行。用它来解决它 d:DataContext =“{d:DesignInstance viewModel:EngineerViewModel,IsDesignTimeCreatable = True}” 并设置一个无参数的新构造函数。 斯科特