새 여백으로 Visual Studio 편집기 확장
텍스트 보기 여백은 여백 컨테이너에 배치되고(ContainerMarginPlacement.KnownValues참조) 다른 여백에 상대적으로 앞이나 후에 순서가 지정됩니다(MarginPlacement.KnownValues참조).
텍스트 보기 여백 공급자는 ITextViewMarginProvider 인터페이스를 구현하고, TextViewMarginProviderConfiguration 구현하여 제공하는 여백을 구성하고, 활성화될 때 CreateVisualElementAsync통해 여백에 호스트할 UI 컨트롤을 제공합니다.
VisualStudio.Extensibility의 확장은 Visual Studio에서 처리되지 않을 수 있으므로 WPF를 텍스트 보기 여백 콘텐츠의 프레젠테이션 계층으로 직접 사용할 수 없습니다. 대신 텍스트 보기 여백에 콘텐츠를 제공하려면 RemoteUserControl 해당 컨트롤에 해당하는 데이터 템플릿을 만들어야 합니다. 아래에는 몇 가지 간단한 예제가 있지만 텍스트 보기 여백 UI 콘텐츠를 만들 때 원격 UI 설명서를 읽는 것이 좋습니다.
/// <summary>
/// Configures the margin to be placed to the left of built-in Visual Studio line number margin.
/// </summary>
public TextViewMarginProviderConfiguration TextViewMarginProviderConfiguration => new(marginContainer: ContainerMarginPlacement.KnownValues.BottomRightCorner)
{
Before = new[] { MarginPlacement.KnownValues.RowMargin },
};
/// <summary>
/// Creates a remotable visual element representing the content of the margin.
/// </summary>
public async Task<IRemoteUserControl> CreateVisualElementAsync(ITextViewSnapshot textView, CancellationToken cancellationToken)
{
var documentSnapshot = await textView.GetTextDocumentAsync(cancellationToken);
var dataModel = new WordCountData();
dataModel.WordCount = CountWords(documentSnapshot);
this.dataModels[textView.Uri] = dataModel;
return new MyMarginContent(dataModel);
}
텍스트 뷰 여백 공급자는 여백 배치를 구성하는 것 외에도 GridCellLength 및 GridUnitType 속성을 사용하여 여백을 배치해야 하는 그리드 셀의 크기를 구성할 수도 있습니다.
텍스트 보기 여백은 일반적으로 텍스트 보기와 관련된 일부 데이터(예: 현재 줄 번호 또는 오류 수)를 시각화하므로 대부분의 텍스트 보기 여백 공급자는 텍스트 보기 이벤트 텍스트 보기 이벤트를 수신 대기하여 텍스트 보기 열기, 텍스트 보기 닫기 및 사용자 입력에 반응할 있습니다.
Visual Studio는 사용자가 여는 적용 가능한 텍스트 보기 수에 관계없이 텍스트 보기 여백 공급자의 인스턴스를 하나만 만들므로 여백에 상태 저장 데이터가 표시되면 공급자는 현재 열려 있는 텍스트 보기의 상태를 유지해야 합니다.
자세한 내용은 단어 계산 여백 샘플을 참조하세요.
콘텐츠를 텍스트 보기 줄에 맞춰야 하는 세로 텍스트 보기 여백은 아직 지원되지 않습니다.