从 WebEdit 命令打开时,Sitecore 设置 SPEAK UI 对话框大小

Sitecore set SPEAK UI dialog size when opening from WebEdit command

我在 Sitecore 的页面编辑器中有一个自定义体验按钮,它引用了一个自定义命令。从此上下文打开 SPEAK 对话框的正确方法是什么?应该如何设置对话框的 width/height?

我有以下命令代码:

public class MySpecialCommand : Sitecore.Shell.Applications.WebEdit.Commands.WebEditCommand
{
    public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
    {
        var parameters = new NameValueCollection();
        //add various parameters etc 
        Context.ClientPage.Start((object) this, "Run", parameters);
    }

    protected void Run(ClientPipelineArgs args)
    {
        if (!args.IsPostBack)
        {           
            string url = "/sitecore/client/your%20apps/somespeakdialog?sc_lang=en&someParam" + args.Parameters["someParam"];
            SheerResponse.ShowModalDialog(url, "100", "200", string.Empty, true);
            args.WaitForPostBack();
        }
        else if (args.HasResult)
        {
            //not got this far yet...
        }
    }
}

我发现对话框的大小与传递给 SheerResponse.ShowModalDialogwidthheight 参数没有任何相似之处。我也尝试过传递以 "px" 为后缀的值,但这没有帮助。

Sitecore 7.5 中基于 SPEAK 的对话框没有开箱即用的设置宽度和高度的功能(在 8.0 中可用)

但是,您可以自定义 \sitecore\shell\Controls\jQueryModalDialogs.html 文件。只需找到并更新以下 if 语句:

if (isSpeakDialog) {
  createdDialog.dialog('option', 'width', size.width);
  createdDialog.dialog('option', 'height', size.height);
}

在 Sitecore 8.0 中添加了一个新方法:

public static ClientCommand ShowModalDialog(ModalDialogOptions options)

您的 SheerResponse.ShowModalDialog(url, "100", "200", string.Empty, true); 将是

SheerResponse.ShowModalDialog(new ModalDialogOptions(url)
{
  Width = "100",
  Height = "200",
  Response = true,
  ForceDialogSize = true
});

ForceDialogSize属性的描述:

Gets or sets a value indicating whether SPEAK dialogs will take into acount <see cref="Width"/> and <see cref="Height"/>.