[英]SQL Server Compact + Entity Framework Design Time Data
I have an application being designed with SQL CE and Entity Framework. 我有一个使用SQL CE和实体框架设计的应用程序。 Is there a practical way to make that data available at design time to databound controls in Visual Studio Express 2012 for Desktop?
有没有一种实用的方法可以在设计时将这些数据提供给Visual Studio Express 2012 for Desktop中的数据绑定控件?
Assuming you're using an MVVM framework such as Caliburn.Micro, you can set the designer datacontext like so : 假设你使用的是MVVM框架如Caliburn.Micro,你可以设置设计师的DataContext像这样 :
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:CaliburnDesignTimeData.ViewModels"
xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=vm:YourViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True"
There are similar ways to do this using other MVVM frameworks. 使用其他MVVM框架也有类似的方法。
Example: 例:
public class YourViewModel : PropertyChangedBase
{
public BindableCollection<Employee> Employees { get; set; }
public YourViewModel
{
Employees = new BindableCollection<Employee>();
if(Execute.InDesignMode)
{
// Add an employee when in design mode, this data will show up in design time
Employees.Add(new Employee
{
Name = "Sample Data Employee"
});
}
}
}
Then bind it in XAML (if the designer datacontext added correctly, the VM's properties will even show up in Intellisense): 然后将其绑定到XAML(如果正确添加了设计器数据上下文,则VM的属性甚至将显示在Intellisense中):
<Window
...
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:CaliburnDesignTimeData.ViewModels"
xmlns:cal="clr-namespace:Caliburn.Micro;assembly=Caliburn.Micro"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type=vm:YourViewModel, IsDesignTimeCreatable=True}"
cal:Bind.AtDesignTime="True"
>
<Grid>
<DataGrid
AutoGenerateColumns="True"
ItemsSource="{Binding Employes}" />
</Grid>
</Window>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.