How to Set the Size of a Teams Dialog in the Microsoft 365 Agents SDK in C#
A Teams dialog is as big as your agent says. A short message fits a small window, and a form with many fields needs a large one. The size goes in the same answer that opens the dialog, as a named size or in pixels.
Syntax
Value = new
{
title = "<title>",
width = <width>,
height = <height>,
card = <the dialog's card>,
},
| Part | What it does |
|---|---|
width | "small", "medium" or "large", or a number of pixels such as 400 |
height | The same choices, for the height |
Microsoft's Invoke and dismiss dialogs describes both kinds of values. Named sizes are a proportion of the available space, 20%, 50%, and 60% for width and 20%, 50%, and 66% for height. Pixels are exact, but Depending on the size of the Teams window and screen resolution, these values might be reduced proportionally while maintaining aspect ratio.
The value is an object, so it holds either a string or a number. The Teams package also has the names as constants, in TaskModuleSizes.
The Example
The agent for this post sends a card with four buttons: small, medium, large and 400x300. Each opens the same one-line dialog in that size. Teams ran in a browser window 1600 pixels wide and 1000 high.
Prerequisites
- An agent that already runs in Microsoft Teams, in a personal chat, with the Teams extension added.
Step 1: Size the Dialog in the Answer
using System.Text.Json.Nodes;
using Microsoft.Agents.Builder;
using Microsoft.Agents.Builder.App;
using Microsoft.Agents.Builder.State;
using Microsoft.Agents.Core.Models;
using Microsoft.Agents.Extensions.MSTeams;
using Microsoft.Teams.Apps.Schema;
using Microsoft.Teams.Apps.TaskModules;
namespace HoSize;
[TeamsExtension]
public partial class SizeAgent : AgentApplication
{
public SizeAgent(AgentApplicationOptions options) : base(options)
{
OnActivity(ActivityTypes.Message, SendCardAsync);
TeamsExtension.TaskModules.OnFetch("size", OpenAsync);
}
// One button per size. Each sends the size it asks for, next to "task": "size".
private Task SendCardAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
JsonArray actions = new();
foreach (string size in new[] { "small", "medium", "large", "400x300" })
{
actions.Add(new JsonObject
{
["type"] = "Action.Submit",
["title"] = size,
["data"] = new JsonObject
{
["msteams"] = new JsonObject { ["type"] = "task/fetch" },
["task"] = "size",
["size"] = size,
},
});
}
JsonObject card = new()
{
["type"] = "AdaptiveCard",
["version"] = "1.5",
["body"] = new JsonArray
{
new JsonObject { ["type"] = "TextBlock", ["text"] = "Dialog sizes", ["size"] = "Large", ["weight"] = "Bolder" },
new JsonObject { ["type"] = "TextBlock", ["text"] = "Open the same dialog in each size.", ["wrap"] = true },
},
["actions"] = actions,
};
return turnContext.SendActivityAsync(
MessageFactory.Attachment(new Attachment { ContentType = ContentTypes.AdaptiveCard, Content = card }),
cancellationToken);
}
// The width and height are either "small", "medium" or "large", or a number of pixels.
private Task<TaskModuleResponse> OpenAsync(ITeamsTurnContext turnContext, ITurnState turnState, TaskModuleRequest request, CancellationToken cancellationToken)
{
string size = request.GetDataString("size");
object width = size;
object height = size;
if (size == "400x300")
{
width = 400;
height = 300;
}
JsonObject card = new()
{
["type"] = "AdaptiveCard",
["version"] = "1.5",
["body"] = new JsonArray
{
new JsonObject { ["type"] = "TextBlock", ["text"] = $"This dialog is {size}.", ["wrap"] = true },
},
};
TaskModuleResponse response = new()
{
Task = new Response
{
Type = TaskModuleResponseTypes.Continue,
Value = new
{
title = $"Size: {size}",
width,
height,
card = new TeamsAttachment { ContentType = AttachmentContentTypes.AdaptiveCard, Content = card },
},
},
};
return Task.FromResult(response);
}
}

- Each button's
datacarries"task": "size"and the size it asks for. OpenAsyncreads that size withGetDataString, and uses it forwidthandheight. For400x300, it sets the numbers400and300instead.widthandheightareobjects, so one variable can hold a string or a number.
Step 2: Open Each Size
Send the agent any message:

Each button opened the dialog at the center of the window. Their measured sizes, in a window 1600 pixels wide and 1000 high:
| Button | width / height sent | Dialog size on screen |
|---|---|---|
| small | "small" / "small" | 320 × 297 |
| medium | "medium" / "medium" | 800 × 567 |
| large | "large" / "large" | 960 × 727 |
| 400x300 | 400 / 300 | 400 × 367 |



![]()
- The widths were 20%, 50% and 60% of the 1600-pixel window, as Microsoft's page says.
- The heights include the dialog's top part, with the app's name, the title and the X: the 300-pixel dialog came out 367 pixels high, 67 more than asked for.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Fixed pixels for every screen | Teams may scale them down in smaller windows, as Microsoft's page says | Prefer the named sizes, which follow the window |
| Expecting the height to be the card's area | The height includes the dialog's top part | Allow for it, or use a named size |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The dialog is taller than the pixels you set | The height includes the dialog's top part | Allow about 67 pixels for it |
| The dialog is smaller than you set | The Teams window is smaller | Use named sizes, or smaller numbers |
FAQ
Can width and height differ?
Yes: they're separate values. Mixing them, such as a medium width with a small height, suits short dialogs with long lines.
Conclusion
Set a Teams dialog's size with width and height in the Continue answer that opens it: small, medium or large for a share of the Teams window, or pixels for an exact size, which Teams may scale down. Named widths came out at 20%, 50% and 60% of the window.
Additional Resources
- Invoke and dismiss dialogs, on Microsoft Learn: Dialog sizing.
- Designing dialogs for your Microsoft Teams app, on Microsoft Learn.
