コード例 #1
0
        //Listing 20-22. Creating a Desktop Client Screen Template Extension

        public void Generate(IScreenTemplateHost host)
        {
            var screenBase = (ScreenPropertyBase)host.PrimaryDataSourceProperty;

            ContentItem groupLayout1 =
                host.AddContentItem(host.ScreenLayoutContentItem,
                                    "GroupLayout1", ContentItemKind.Group);

            string entityTypeFullName =
                ((ScreenProperty)host.PrimaryDataSourceProperty).PropertyType;

            var entityTypeName =
                ((ScreenProperty)host.PrimaryDataSourceProperty).PropertyType.Split(
                    ":".ToArray()).LastOrDefault();

            ScreenProperty screenProperty1 =
                (ScreenProperty)host.AddScreenProperty(entityTypeFullName,
                                                       entityTypeName + "Property");

            //make the default id parameter not required
            var idParameter = host.PrimaryDataSourceParameterProperties.FirstOrDefault();

            ((ScreenProperty)idParameter).PropertyType =
                "Microsoft.LightSwitch:Int32?";

            //This creates an AutoCompleteBox for the item
            var screenPropertyContentItem = host.AddContentItem(
                groupLayout1, "LocalProperty", screenProperty1);

            host.SetContentItemView(screenPropertyContentItem,
                                    "Microsoft.LightSwitch.RichClient:RowsLayout");

            host.ExpandContentItem(screenPropertyContentItem);

            string codeTemplate = "";

            if (codeTemplates.TryGetValue(
                    host.ScreenCodeBehindLanguage, out codeTemplate))
            {
                host.AddScreenCodeBehind(String.Format(codeTemplate,
                                                       Environment.NewLine,
                                                       host.ScreenNamespace,
                                                       host.ScreenName,
                                                       screenBase.Name,
                                                       idParameter.Name,
                                                       screenProperty1.Name,
                                                       entityTypeName));
            }
        }
コード例 #2
0
        //Listing 20-25. Creating an HTML Client Screen Template Extension


        public void Generate(IScreenTemplateHost host)
        {
            //1 Add a tab
            var screenTab = host.AddContentItem(host.ScreenTabPagesContentItem,
                                                "Tab1", ContentItemKind.Group);

            // 2 Add a group and data items
            ContentItem screenGroup =
                host.AddContentItem(screenTab,
                                    "Group1", host.PrimaryDataSourceProperty);

            screenGroup.View = "Microsoft.LightSwitch.MobileWeb:RowsLayout";
            host.ExpandContentItem(screenGroup,
                                   disableNavigationPropertyGeneration: false,
                                   disableGeneratedPropertyGeneration: false);

            //3 Add a popup called ConfirmDelete
            var popupControl = host.AddContentItem(
                host.ScreenDialogPagesContentItem, "ConfirmDelete",
                ContentItemKind.Group);

            //4.1 Add a string property for the popup title
            ScreenProperty titleProperty =
                (ScreenProperty)host.AddScreenProperty(":String?", "PopupTitle");

            //4.2 Add a text control to the popup and bind it to the string property
            var titleControl = host.AddContentItem(popupControl,
                                                   "PopupTitle", titleProperty);

            titleControl.View = "Microsoft.LightSwitch.MobileWeb:Text";

            //5 Add OK and Cancel methods and add a command to the popup
            ScreenMethod    methodDoDelete   = host.AddScreenMethod("DoDelete");
            CallExpression  callExpDoDelete  = host.CreateCallExpression(methodDoDelete.Id);
            ChainExpression chainExpDoDelete =
                host.CreateChainExpression(callExpDoDelete);
            ScreenExpressionTree expTreeDoDelete =
                new ScreenExpressionTree()
            {
                Body = chainExpDoDelete
            };
            ContentItem commandDoDelete = host.AddContentItem(
                popupControl,
                "DoDelete",
                ContentItemKind.Command);

            host.SetDisplayName(commandDoDelete, "OK");

            //6.1 Create a method to show the popup window
            var commandShowPopup = new ContentItem();

            commandShowPopup.Kind = ContentItemKind.Command;
            ScreenMethod         methodShowPopup  = host.AddScreenMethod("ShowPopup");
            CallExpression       callExpression   = host.CreateCallExpression(methodShowPopup.Id);
            ChainExpression      chainExpression  = host.CreateChainExpression(callExpression);
            ScreenExpressionTree expTreeShowPopup =
                new ScreenExpressionTree()
            {
                Body = chainExpression
            };

            host.SetControlPropertyExpressionTree(
                commandShowPopup,
                "Microsoft.LightSwitch.MobileWeb:RootControl",
                "Tap",
                expTreeShowPopup);

            //6.2 Configure the button to show the trash icon
            ConstantExpression constExpTrashIcon = new ConstantExpression();

            constExpTrashIcon.ResultType = ":String";
            constExpTrashIcon.Value      = "msls-trash";
            ChainExpression chainExpTrashIcon =
                host.CreateChainExpression(constExpTrashIcon);
            ScreenExpressionTree expTreeTrashIcon =
                new ScreenExpressionTree()
            {
                Body = chainExpTrashIcon
            };

            host.SetControlPropertyExpressionTree(
                commandShowPopup,
                "Microsoft.LightSwitch.MobileWeb:RootCommand",
                "Icon",
                expTreeTrashIcon);

            host.SetDisplayName(commandShowPopup, "ShowPopup");
            screenTab.CommandItems.Add(commandShowPopup);

            //7 Add the JavaScript code for the methods

            StringBuilder sb = new StringBuilder();

            sb.Append("{0}myapp.{1}.created = function (screen) {{");
            sb.Append("{0}    screen.PopupTitle = 'Confirm Delete';");
            sb.Append("{0}}};");

            sb.Append("{0}myapp.{1}.DoDelete_execute = function (screen) {{");
            sb.Append("{0}    screen.{2}.deleteEntity();");
            sb.Append("{0}    return myapp.commitChanges();");
            sb.Append("{0}}};");

            sb.Append("{0}myapp.{1}.ShowPopup_execute = function (screen) {{");
            sb.Append("{0}    return screen.showPopup('ShowPopup');");
            sb.Append("{0}}};");

            host.AddScreenCodeBehind(String.Format(sb.ToString(),
                                                   Environment.NewLine,
                                                   host.ScreenName,
                                                   host.PrimaryDataSourceProperty.Name
                                                   ));
        }