레이블 모양의 컨트롤에 짧은 FlowDocument
문자열을 표시하는 방법을 찾고 있습니다.레이블과 같은 컨트롤에서 짧은 읽기 전용 FlowDocument를 표시하는 방법
WPF에서 사용자는 RichTextBox
에 텍스트를 입력 할 수 있습니다. 결과는 FlowDocument
문자열입니다. I는 Label
에 해당 텍스트를 제시하는 방법을 찾고 있어요 :
- 은 사용자가 편집하거나 텍스트 (마우스로) 선택할 수 없습니다합니다.
- 모든 텍스트를 수용하기 위해 컨트롤이 확장되어야하는 일반 레이블처럼 스크롤 막대가 없어야합니다.
- 마우스가 레이블에있는 동안 스크롤하면 컨트롤의 부모가 스크롤해야하는 컨트롤
- 가능한 한 가벼운 컨트롤이어야합니다. (아마도
FlowDocumentScrollViewer
이외의 제어 권한을 상속)
나는 FlowDocumentScrollViewer
을 상속 다음과 같은 구현을 가지고 있지만 나는 더욱 향상된 기능이 있어야 확신합니다.
public class FlowDocumentViewer : FlowDocumentScrollViewer
{
public FlowDocumentViewer()
{
this.SetValue(ScrollViewer.CanContentScrollProperty, false);
this.SetValue(ScrollViewer.VerticalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden);
this.Padding = new Thickness(-17);
this.Document = new FlowDocument();
}
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
e.Handled = false;
}
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(FlowDocumentViewer), new UIPropertyMetadata(string.Empty, TextChangedHandler));
private static void TextChangedHandler(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue.Equals(string.Empty))
return;
FlowDocumentViewer fdv = (FlowDocumentViewer)d;
fdv.Document.Blocks.Clear();
using (MemoryStream stream = new MemoryStream(UTF8Encoding.UTF8.GetBytes(e.NewValue.ToString())))
{
Section content = XamlReader.Load(stream) as Section;
fdv.Document.Blocks.Add(content);
}
}
}