介绍
在本文中,我们将在它们的Silverlight调度器控制中处理一个复杂的多表控件。 这是一个功能丰富的控件,具有大量功能。 这是值得的努力,使它工作的。 在本文中,我们将演示在集成复杂控件时可以使用的方法。
背景
的优势在于它们能够为聚集数据提供大量的Silverlight 控件。 LightSwitch帮助网站以前覆盖了他们的extension扩展: 使用OLAP为LightSwitch服务提供支持的 。 控件的设计主要由最终用户配置。 Control控制扩展 Makers Dilemma解释LightSwitch控制扩展扩展易于使用,但配置有限。
控件之所以如此复杂,是因为它同时与几个表通信。 它允许你存储联系人,资源,以及的约会。 这些表加入你自己的应用程序时,将指向你的数据。 例如使用这里控件,你可以创建允许员工保留会议室的应用程序。
LightSwitch
调度程序控件是普通的Silverlight控件。 LightSwitch'带到表格'的能力是多少分钟内创建应用程序的能力。 我读了控件的说明之后,就可以在 5分钟内创建所需的表。 在那一点上,有 90%个应用程序。
调度程序控件
运行示例( 你可以在下载页面下载代码。) 时,将看到一个提示,指示你使用评估版本。
单击'x'以关闭弹出窗口。
双击双击打开一个弹出式菜单,允许你创建或者编辑的约会。
你也可以表示资源附加到的约会。 你可以选择现有的资源,或者添加和删除资源。
你还可以表示联系人附加到的约会。 你可以选择现有的联系人,或者添加和删除联系人。
同样的选项可以用于类别。 在本例中,我们关闭了添加新的类别的能力。
计划者控制真的非常出色,能够对这些数据进行分组,并通过联系人Contact显示日历。
。或者资源。
。或者。
它还以天,周和工作日显示数据。
你可以创建定期约会。
它甚至会弹出提醒。
更多关于调度程序控件的信息
你可以在这里链接中看到所有收费的控件的实时演示: http://demo.componentone.com/Silverlight/ControlExplorer/
你可以在以下位置获得计划程序控制的完整文档: http://helpcentral.componentone.com/nethelp/c1schedulerSL/。
但是,如果你下载并安装演示包插件。
。and然后点击安装的样例。
你将发现可以运行项目。 然而,这些是普通的项目,因此你需要知道如何将它们绑定在。 好消息是,无论我们多么复杂,可以使用任何收费的Silverlight控件。
实现控件
整个收费解决方案由三个实体( 表格) 组成,一个包含进度控制的Silverlight项目。 按收费控制是放置在收费 Calendar Calendar屏幕的唯一项目,这是该应用程序中唯一收费的屏幕。
通过查看数据源和控件设计用来使用( 然后通过阅读文档代码,并查看示例代码)的字段来确定实体的架构。
Silverlight项目
( 说明: 为实现的Silverlight控制创建一个LightSwitch定制的Silverlight控件以为代价实现Silverlight的Silverlight控制( ) )。
,Silverlight项目中,我们增加了对ComponentOne程序集和程序集的引用。 同时注意,当控件放在LightSwitch屏幕上时,同样的程序集需要再次引用。 有关这里示例,请参见实现这里控件的步骤: 使用中的Telerik富文本编辑器。
在示例ComponentOne代码中借用了大量的XAML XAML XAML来显示落差和按钮,但是以下的XAML 显示实际的收费计划程序控件:
<c1:C1SchedulerGrid.Row="2"Grid.Column="1"x:Name="sched1"GroupPageSize="2"StyleChanged="sched1_StyleChanged"UserDeletingAppointment="sched1_UserDeletingAppointment"><c1sched:C1Scheduler.Settings><c1sched:C1SchedulerSettingsAllowContactsEditing="True"AllowResourcesEditing="True"AllowCategoriesEditing="False"AllowCategoriesMultiSelection="True"AllowResourcesMultiSelection="True"AllowContactsMultiSelection="True"FirstVisibleTime="08:00:00"/></c1sched:C1Scheduler.Settings></c1:C1Scheduler>
但是,如果 LightSwitch开始绑定到控件,则该控件会引发错误,而不是实际传递任何数据,这将引发错误。
如果绑定是错误的或者错误的,则通常会失败。 计划程序控制 complex复杂,并引发错误。 因此,我们代码中的绑定代码来解决这个问题。
实际上,在我们知道 实际拥有数据来提供(。是,使用Silverlight值转换器也可能实现这里功能) 之前,我们实际上不会设置任何绑定。
当 绑定数据到控件时,我们将调用一个属性,该属性将调用以下方法:
privatestaticvoid OnScheduleControlPropertyChanged(
DependencyObject d, DependencyPropertyChangedEventArgs e)
{
// Get the DataContext ScheduleControl objScheduleControl = (ScheduleControl)d;
IContentItem contentItem = (IContentItem)objScheduleControl.DataContext;
if (contentItem.Details!= null)
{
// Fill the Group drop down objScheduleControl.cmbGroup.Items.Add("None");
objScheduleControl.cmbGroup.Items.Add("Category");
objScheduleControl.cmbGroup.Items.Add("Resource");
objScheduleControl.cmbGroup.Items.Add("Contact");
objScheduleControl.cmbGroup.SelectedIndex = 0;
// Fill the Views drop down objScheduleControl.cmbView.Items.Add("Day");
objScheduleControl.cmbView.Items.Add("Working Week");
objScheduleControl.cmbView.Items.Add("Week");
objScheduleControl.cmbView.Items.Add("Month");
objScheduleControl.cmbView.SelectedIndex = 3;
// Set mapping between ContactStorage and Contact table columns BaseObjectMappingCollection<Contact> ContactMappings =
objScheduleControl.sched1.DataStorage.ContactStorage.Mappings;
ContactMappings.IndexMapping.MappingName = "Id";
ContactMappings.IdMapping.MappingName = "GuidId";
ContactMappings.CaptionMapping.MappingName = "Caption";
ContactMappings.ColorMapping.MappingName = "Color";
ContactMappings.TextMapping.MappingName = "Text";
objScheduleControl.sched1.DataStorage.ContactStorage.DataMember = "Contacts";
objScheduleControl.sched1.DataStorage.ContactStorage.DataSource = contentItem.Screen;
// Set mapping between ResourceStorage and Resource table columns BaseObjectMappingCollection<Resource> ResourceStorage =
objScheduleControl.sched1.DataStorage.ResourceStorage.Mappings;
ResourceStorage.IndexMapping.MappingName = "Id";
ResourceStorage.IdMapping.MappingName = "GuidId";
ResourceStorage.CaptionMapping.MappingName = "Caption";
ResourceStorage.ColorMapping.MappingName = "Color";
ResourceStorage.TextMapping.MappingName = "Text";
objScheduleControl.sched1.DataStorage.ResourceStorage.DataMember = "Resources";
objScheduleControl.sched1.DataStorage.ResourceStorage.DataSource = contentItem.Screen;
// Set mapping between AppointmentStorage and Appointment table columns AppointmentMappingCollection AppointmentMappings =
objScheduleControl.sched1.DataStorage.AppointmentStorage.Mappings;
AppointmentMappings.IndexMapping.MappingName = "Id";
AppointmentMappings.IdMapping.MappingName = "GuidId";
AppointmentMappings.Subject.MappingName = "Subject";
AppointmentMappings.Body.MappingName = "Body";
AppointmentMappings.End.MappingName = "TimeEnd";
AppointmentMappings.Start.MappingName = "TimeStart";
AppointmentMappings.Location.MappingName = "Location";
AppointmentMappings.AppointmentProperties.MappingName = "Properties";
objScheduleControl.sched1.DataStorage.AppointmentStorage.DataMember = "Appointments";
objScheduleControl.sched1.DataStorage.AppointmentStorage.DataSource =
contentItem.Screen;
}
注意,我们还指出如何将每个数据源映射为 LightSwitch的Entities。
Every control,所以重要的概念是你可以获得的实例,检查它实际有数据,并绑定到你的Silverlight控件。
删除问题
对于复杂控件,如果控件不按预期的方式进行通信,则可能会遇到问题,并且你会收到错误消息。 当你试图删除一个收费的约会项目时,这种情况发生。
当计划程序控制删除一个约会时,需要通过在GUID中找到该记录,并在LightSwitch中明确删除它来删除记录。
这是使用的代码:
privatevoid sched1_UserDeletingAppointment(object sender,
C1.Silverlight.Schedule.AppointmentActionEventArgs e)
{
// Get a reference to the LightSwitch DataContext var objDataContext = (IContentItem)this.DataContext;
// Get a reference to the LightSwitch Screenvar Screen =
(Microsoft.LightSwitch.Client.IScreenObject)objDataContext.Screen;
// Delete the appointment in LightSwitch Screen.Details.Dispatcher.BeginInvoke(() => {
string strGuid = Convert.ToString(e.Appointment.Key[0]);
Guid DeletedGuidId = new Guid(strGuid);
LightSwitchApplication.DataWorkspace DataWorkspace =
(Screen.Details.DataWorkspace as LightSwitchApplication.DataWorkspace);
LightSwitchApplication.Appointment DeletedAppointment =
DataWorkspace.ApplicationData.Appointments
. Where(x => x.GuidId == DeletedGuidId).FirstOrDefault();
if (DeletedAppointment!= null)
{
DeletedAppointment.Delete();
}
});
}
无法初始化EntityObject类的新实例,因为环境IDataWorkspace不可用。 请使用指定EntitySet的构造函数。由于你在上面收到了这个博客文章,所以解决方案是执行你想要在背后的屏幕上执行的任何操作。
we一步是在 public
控件中添加一个属性,以允许的LightSwitch代码以编程方式访问的Silverlight控件。
然后,在 LightSwitch 屏幕代码中使用以下代码:
using System;using Microsoft.LightSwitch.Presentation;using Microsoft.LightSwitch.Presentation.Extensions;using SilverlightLibrary;namespace LightSwitchApplication
{
publicpartialclass Calendar
{
// The following methods are by Raleigh Johnson // http://ComponentOne.compartialvoid Calendar_Created()
{
// Get an instance of the ComponentOne Scheduler Control IContentItemProxy schedProxy = this.FindControl("Appointments");
// Create a handler to fire when the control is actually available schedProxy.ControlAvailable +=
new EventHandler<ControlAvailableEventArgs>(schedProxy_ControlAvailable);
}
void schedProxy_ControlAvailable(object sender, ControlAvailableEventArgs e)
{
// Get an instance of the ComponentOne Scheduler Control ScheduleControl sc = e.Control as ScheduleControl;
// Create an event that will fire when an Appointment is being created sc.Scheduler.DataStorage.AppointmentStorage.AddingNew += (obj, args) => {
// Create a new Appointment in LightSwitch Appointment app = new Appointment
(this.DataWorkspace.ApplicationData.Appointments);
// Set the NewObject in the ComponentOne Scheduler Control args.NewObject = app;
};
// Create an event that will fire when a Contact is being created sc.Scheduler.DataStorage.ContactStorage.AddingNew += (obj, args) => {
// Create a new Contact in LightSwitch Contact app = new Contact(this.DataWorkspace.ApplicationData.Contacts);
// Set the NewObject in the ComponentOne Scheduler Control args.NewObject = app;
};
// Create an event that will fire when a Resource is being created sc.Scheduler.DataStorage.ResourceStorage.AddingNew += (obj, args) => {
// Create a new Resource in LightSwitch Resource app = new Resource(this.DataWorkspace.ApplicationData.Resources);
// Set the NewObject in the ComponentOne Scheduler Control args.NewObject = app;
};
}
}
}
大多数控制不会是这样难
我决定处理这个控制,因为我知道它很难。 我希望能够处理复杂的业务应用程序。 可以在普通的 Silverlight应用程序中完成的任何事情都可以用。
特别鸣谢
这篇文章是不可能的,如果没有的ComponentOne。
An extra extra提供额外的代码,以便正确创建新的约会提供代码 required。
我也要感谢贵公司的ComponentOne。
更多LightSwitch计划程序控制
Paul Patterson有一个关于使用 Telerik计划程序的教程: