How to customize the Add/edit window in lightswitch

Source: Internet
Author: User

Lightswitch has built-in new and edit functions. One is to click Add in the functional area of the table or List window. A mode window is displayed. However, the problem is that there is no way to typeset the interface elements. If there are multiple lines of text boxes, this window can only be a single row. The other is to add a new interface and call it. However, instead of a Mode window, a new tab is opened to add a new one.

The above two modes have their own advantages and disadvantages. This article discusses how to add new interfaces in the main window, and arrange elements on the new interfaces.

There is a mode window in the layout provided by lightswitch. You can set a mode window in the main interface to make the window invisible and show no buttons at the same time. In this way, we need to call the mode window. The new layout below can be used freely.




The layout in the mode window is not described here. You can handle it as required.


The following shows how to call this mode window to display the new interface. First, switch the project to the file view and define a mode window processing class.

Using system; using system. net; using system. windows; using system. windows. controls; using system. windows. documents; using system. windows. ink; using system. windows. input; using system. windows. media; using system. windows. media. animation; using system. windows. shapes; using Microsoft. lightswitch. client; using Microsoft. lightswitch; using Microsoft. lightswitch. presentation; using Microsoft. lightswitch. presentation. Extensions; using system. componentmodel; using Microsoft. lightswitch. threading; namespace lightswitchapplication {public class modalwindowhelper {private ivisualcollection _ collection; private string _ dialogname; private string _ entityname; private iscreenobject _ screen; private icontentitemproxy _ window; private ientityobject _ entity; public modalwindowhelper (ivisualcollection visualcollection, St Ring dialogname, string entityname = "") {_ collection = visualcollection; _ dialogname = dialogname; _ entityname = (entityname! = "")? Entityname: _ collection. details. getModel (). elementtype. name); _ screen = _ collection. screen;} public void initializeui () {_ window = _ screen. findcontrol (_ dialogname); _ window. controlavailable + = (Object S, controlavailableeventargs e) => {var window = (childwindow) E. control; window. closed + = (Object S1, eventargs E1) =>{ dialogclosed (S1) ;};}} public bool canadd () {return (_ collection. canad Dnew = true);} public bool caneditselected () {return (_ collection. selecteditem! = NULL);} public void addentity () {_ window. displayname = string. format ("add {0}", _ entityname); _ collection. addnew (); openmodalwindow ();} public void editselectedentity () {_ window. displayname = string. format ("Edit {0}", _ entityname); openmodalwindow ();} private void openmodalwindow () {_ entity = _ collection. selecteditem as ientityobject; _ screen. openmodalwindow (_ dialogname);} public void dialogo K () {If (_ entity! = NULL) {_ screen. closemodalwindow (_ dialogname) ;}} public void dialogcancel () {If (_ entity! = NULL) {_ screen. closemodalwindow (_ dialogname); discardchanges () ;}} public void dialogclosed (Object sender) {var window = (childwindow) sender; If (window. dialogresult. hasvalue = false) {discardchanges () ;}} private void discardchanges () {If (_ entity! = NULL) {_ entity. Details. discardchanges ();}}}}


2. Rewrite the add, edit, or delete code of the table or list to be added in the main form, for example, canexecute and execute code.



Public partial class deptmentlistdetail {modalwindowhelper deptdialoghelper = NULL; partial void deptmentitemlistaddandeditnew_canexecute (ref bool result) {result = deptdialoghelper. canadd ();} partial void deptmentitemlistaddandeditnew_execute () {deptdialoghelper. addentity ();} partial void deptmentlistdetail_created () {deptdialoghelper. initializeui (); If (deptment. count> 0) deptment. selected Item = deptment. first ();} partial void editdialogok_execute () {deptdialoghelper. dialogok ();} partial void editdialogcancel_execute () {deptdialoghelper. dialogcancel ();} partial void deptmentitemlisteditselected_canexecute (ref bool result) {result = deptdialoghelper. caneditselected ();} partial void deptmentitemlisteditselected_execute () {deptdialoghelper. editselectedentity ();} partial void Deptmentlistdetail_initializedataworkspace (list <idataservice> savechangesto) {// write your code here. Deptdialoghelper = new modal?whelper (deptment, "depteditdialog", "department information ");}}

Please rewrite the relevant Code separately, but note that deptdialoghelper = new modal?whelper (deptment, "depteditdialog", "department information"); depteditdialog is the mode window name.

Run the following command to see how it works.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.