Visual Studio 대화 상자 만들기
대화 상자는 사용자에게 정보를 요청하거나 기능 동작의 사용자 지정을 허용하는 방법입니다. 예를 들어 도구/옵션 대화 상자에는 사용자가 테마, 편집기 및 문서 탭과 같은 기능에 대한 동작을 제어할 수 있는 개별 페이지가 있습니다.
시작하기
시작하려면 이 시작 섹션에서 프로젝트 만들기 섹션을 따릅니다.
대화 작업
이 가이드는 대화 작업 시 주요 사용자 시나리오를 다루도록 설계되었습니다.
만들기 대화
새 확장성 모델을 사용하여 도구 창을 만드는 것은 Shell Extensibility 도우미에서 ShowDialogAsync 메서드를 호출하고 대화 내용을 전달하는 것처럼 간단합니다.
ShowDialogAsync
이 ShowDialogAsync 메서드에는 익숙해져야 하는 몇 가지 오버로드가 있습니다.
오버로드
ShowDialogAsync(content,cancellationToken)
ShowDialogAsync(content,title,cancellationToken)
ShowDialogAsync(content,options,cancellationToken)
ShowDialogAsync(content,title,options,cancellationToken)
매개 변수
이름 | 형식 | 설명 |
---|---|---|
콘텐츠 | Microsoft.VisualStudio.RpcContracts.RemoteUI.IRemoteUserControl | 기사 내용.대화상자 |
title | System.String | 대화 상자의 제목입니다. |
options | Microsoft.VisualStudio.RpcContracts.Notifications.DialogOption | 대화 상자를 표시하는 옵션입니다. |
cancellationToken | System.Threading.CancellationToken | 대화 상자를 취소할 CancellationToken 입니다. |
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
// Ownership of the RemoteUserControl is transferred to Visual Studio, so it shouldn't be disposed by the extension
#pragma warning disable CA2000 // Dispose objects before losing scope
var control = new MyDialogControl(null);
#pragma warning restore CA2000 // Dispose objects before losing scope
await this.Extensibility.Shell().ShowDialogAsync(control, cancellationToken);
}
이 RemoteUserControl 만들기 에 대한 자세한 내용은 리모트 UI를 참조하십시오.
대화 상자 제목 사용자 지정
확장에 대화 상자가 표시되면 대화 상자의 캡션 영역에 표시되는 사용자 지정 제목 문자열을 제공할 수 있습니다.
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
// Ownership of the RemoteUserControl is transferred to Visual Studio, so it shouldn't be disposed by the extension
#pragma warning disable CA2000 // Dispose objects before losing scope
var control = new MyDialogControl(null);
#pragma warning restore CA2000 // Dispose objects before losing scope
await this.Extensibility.Shell().ShowDialogAsync(control, "My Dialog Title", cancellationToken);
}
대화 상자 단추 사용자 지정
IDE에 대화 상자가 표시되면 미리 정의된 대화 단추와 기본 작업의 특정 조합을 선택할 수 있습니다. 미리 정의된 단추 및 작업 조합은 .에서 Microsoft.VisualStudio.RpcContracts.Notifications.DialogOption
찾을 수 있습니다.
또한 다음에서 단추와 기본 작업의 고유한 조합을 만들 수 있습니다.
Microsoft.VisualStudio.RpcContracts.Notifications.DialogButton
public enum DialogButton { // Hides all of the dialog buttons. None, // Shows a single close button. Close, // Shows a single OK button. OK, // Shows an OK and Cancel button. OKCancel }
Microsoft.VisualStudio.RpcContracts.Notifications.DialogResult
public enum DialogResult { // The dialog was closed via the System.Threading.CancellationToken or using an // action provided by the Microsoft.Visual Studio.RpcContracts.RemoteUI.IRemoteUserControl // content. None, // The user clicked the Close button. Close, // The user clicked the OK button. OK, // The user clicked the Cancel button, or clicked the nonclient close button, or // pressed the Esc key. Cancel }
예제
취소 단추 추가:
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
// Ownership of the RemoteUserControl is transferred to Visual Studio, so it shouldn't be disposed by the extension
#pragma warning disable CA2000 // Dispose objects before losing scope
var control = new MyDialogControl(null);
#pragma warning restore CA2000 // Dispose objects before losing scope
await this.Extensibility.Shell().ShowDialogAsync(control, DialogOption.OKCancel, cancellationToken);
}
대화 상자 단추 없음:
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
// Ownership of the RemoteUserControl is transferred to Visual Studio, so it shouldn't be disposed by the extension
#pragma warning disable CA2000 // Dispose objects before losing scope
var control = new MyDialogControl(null);
#pragma warning restore CA2000 // Dispose objects before losing scope
await this.Extensibility.Shell().ShowDialogAsync(control, new DialogOption(DialogButton.None, DialogResult.None), cancellationToken);
}
대화 상자 결과 가져오기
사용자가 대화 상자를 긍정적으로 닫거나 해제했는지 여부를 알아야 하는 경우 호출을 대기할 ShowDialogAsync
수 있으며 사용자가 수행한 작업을 나타내는
public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
// Ownership of the RemoteUserControl is transferred to Visual Studio, so it shouldn't be disposed by the extension
#pragma warning disable CA2000 // Dispose objects before losing scope
var control = new MyDialogControl(null);
#pragma warning restore CA2000 // Dispose objects before losing scope
DialogResult result = await this.Extensibility.Shell().ShowDialogAsync(control, "My Dialog Title", DialogOption.OKCancel, cancellationToken);
if (result == DialogResult.OK)
{
// User clicked the OK button
}
}
다음 단계
대화 상자를 사용하여 확장을 만드는 전체 예제는 DialogSample 샘플을 참조하세요.