2009-11-05 2 views
2

레이블 모양의 컨트롤에 짧은 FlowDocument 문자열을 표시하는 방법을 찾고 있습니다.레이블과 같은 컨트롤에서 짧은 읽기 전용 FlowDocument를 표시하는 방법

WPF에서 사용자는 RichTextBox에 텍스트를 입력 할 수 있습니다. 결과는 FlowDocument 문자열입니다. I는 Label에 해당 텍스트를 제시하는 방법을 찾고 있어요 :

  1. 은 사용자가 편집하거나 텍스트 (마우스로) 선택할 수 없습니다합니다.
  2. 모든 텍스트를 수용하기 위해 컨트롤이 확장되어야하는 일반 레이블처럼 스크롤 막대가 없어야합니다.
  3. 마우스가 레이블에있는 동안 스크롤하면 컨트롤의 부모가 스크롤해야하는 컨트롤
  4. 가능한 한 가벼운 컨트롤이어야합니다. (아마도 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); 
     } 
    } 
} 

답변

0

IsReadOnly를 설정해 보셨습니까?

<RichTextBox IsReadOnly="True"/> 
0

나는이 XAML은 사용자의 요구 사항을 모두 충족 생각; 그것은 사용자 컨트롤을 만드는 것이 사소한 일입니다. RichTextBoxDocument 속성을 설정하는 FlowDocument 종속성 속성을 구현하기 만하면됩니다.

아래에서 볼 수있는 대부분의 내용은 그리스어로 된 텍스트이므로 Kaxaml 등에 붙여 넣을 때의 기능을 볼 수 있습니다. 그것의 핵심은 마우스 이벤트 또는 키 입력을 캡처하지 않도록 Border이 투명한 RichTextBox을 포함하는 Grid입니다.

<Page 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <DockPanel Margin="100"> 
    <ScrollViewer> 
     <StackPanel> 
     <Grid> 
      <RichTextBox Background="Coral"> 
      <FlowDocument> 
       <Paragraph> 
       Gluten-free pariatur exercitation laboris, salvia nisi excepteur. Elit quis PBR, jean shorts DIY excepteur tofu retro. Nulla art party farm-to-table, banh mi labore wes anderson marfa Austin portland carles tattooed 8-bit. Skateboard farm-to-table sed, lomo proident iphone mustache. Keffiyeh magna freegan mollit. Seitan viral consequat elit deserunt, occaecat vero tempor. Terry richardson esse mollit, anim chambray DIY squid.   </Paragraph> 
      </FlowDocument> 
      </RichTextBox> 
      <Border Background="Transparent"/> 
     </Grid> 
     <Grid> 
      <RichTextBox Background="AliceBlue"> 
      <FlowDocument> 
       <Paragraph> 
       Marfa locavore duis, chambray homo irure culpa et high life skateboard. Readymade sartorial odio deserunt. Dolore placeat scenester reprehenderit tattooed nisi. DIY fugiat tempor raw denim. Incididunt sapiente echo park ut yr, deserunt non williamsburg quis. Pitchfork nihil nisi etsy next level elit minim eu, id twee vero exercitation wes anderson. Ullamco beard delectus, before they sold out homo aliquip craft beer esse cillum mlkshk.   </Paragraph> 
      </FlowDocument> 
      </RichTextBox> 
      <Border Background="Transparent"/> 
     </Grid> 
     <Grid> 
      <RichTextBox Background="Goldenrod"> 
      <FlowDocument> 
       <Paragraph> 
       Laborum cliche quinoa odio nostrud Austin, dolor 3 wolf moon craft beer brunch ex vice. Excepteur ullamco fugiat, shoreditch assumenda squid sapiente craft beer viral vice non incididunt tempor. Ullamco gluten-free veniam, elit fugiat sustainable thundercats wolf fap Austin id nihil viral. Sartorial photo booth Austin, pitchfork labore PBR nisi cardigan dolore. Seitan dolor letterpress, banksy organic biodiesel tattooed aliqua. Letterpress ea 3 wolf moon, cosby sweater williamsburg ethical portland reprehenderit wayfarers nostrud beard laboris. Blog ethical trust fund, quinoa vegan skateboard sed art party messenger bag biodiesel do.   
       </Paragraph> 
      </FlowDocument> 
      </RichTextBox> 
      <Border Background="Transparent"/> 
     </Grid> 
     <Grid> 
      <RichTextBox Background="AntiqueWhite"> 
      <FlowDocument> 
       <Paragraph> 
       Assumenda ad aute cred est. Beard elit fugiat brunch, proident nulla 8-bit. Cardigan sapiente 8-bit tempor put a bird on it duis lo-fi. VHS before they sold out commodo, occaecat raw denim artisan dolor photo booth ex gentrify proident readymade ad. Artisan duis thundercats ex, 8-bit ut williamsburg portland seitan cred vinyl brooklyn. Aute deserunt beard cliche, you probably haven't heard of them commodo artisan tumblr irony put a bird on it VHS excepteur american apparel. Voluptate PBR artisan ut banksy, nostrud organic vero fap anim american apparel trust fund do exercitation.   </Paragraph> 
      </FlowDocument> 
      </RichTextBox> 
      <Border Background="Transparent"/> 
     </Grid> 
     </StackPanel> 
    </ScrollViewer> 
    <TextBlock/> 
    </DockPanel> 
</Page>