简体   繁体   English

SQL Server Compact +实体框架设计时间数据

[英]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.

相关问题 具有实体框架的SQL Server Compact Edition - SQL Server Compact Edition with Entity Framework 将Entity Framework 6与SQL Server Compact 4一起使用 - Using Entity Framework 6 with SQL Server Compact 4 如何从 SQL 服务器紧凑型 C# 在 Entity Framework 中更快地读取数据 - How to read data faster in Entity Framework from SQL Server Compact C# 使用Entity Framework Async方法和SQL Server Compact阻止行为 - Blocking behaviour with Entity Framework Async methods and SQL Server Compact 从实体框架上下文获取SQL Server Compact文件的路径? - Get path to SQL Server Compact file from Entity Framework context? 将SQL Server Compact 4.0.0.1与Entity Framework 4.3一起使用 - Using SQL Server Compact 4.0.0.1 with Entity Framework 4.3 在带有实体框架 6.4 的 SQL 服务器紧凑型中无法使用 IDENTITY_INSERT - Not working IDENTITY_INSERT in SQL Server Compact with Entity Framework 6.4 实体框架+ SQL Server Compact + WPF / WinForms =缓慢的用户界面? - Entity Framework + SQL Server Compact + WPF/WinForms = Sluggish UI? 实体框架和SQL Server Compact-数据库提供程序不兼容 - Entity Framework and SQL Server compact - database provider is incompatible 将SQL Server Compact与实体框架一起使用时的UpdateException - UpdateException when using SQL Server Compact with Entity Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM