2011-10-07 5 views
1

MS Word에서 텍스트를 입력 할 때와 같은 방식으로 동작하도록 FlowDocument의 스타일을 지정하려고합니다. 지금 당장 나는 listitem 내에서 단락 여백을 붙잡고있다. 이 XAML을 사용하여WPF FlowDocument - 단락의 목록 항목

FlowDocument preview

: 나는 그냥 내가 원하는 방식에 대해 살펴 만든

<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <FlowDocument.Resources> 

     <Style TargetType="Paragraph"> 
      <Setter Property="Margin" Value="0,0,0,20" /> 
      <Style.Triggers> 
       <DataTrigger Binding="{Binding Margin, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListItem}, AncestorLevel=1}}" Value="0"> 
        <Setter Property="Margin" Value="5" /> 
       </DataTrigger> 
      </Style.Triggers> 
     </Style> 

     <Style TargetType="{x:Type List}"> 
      <Setter Property="Margin" Value="5" /> 
     </Style> 

    </FlowDocument.Resources> 

    <List> 
     <ListItem> 
      <Paragraph>Bullet1</Paragraph> 
     </ListItem> 
     <ListItem> 
      <Paragraph>Bullet2</Paragraph> 
      <List> 
       <ListItem> 
        <Paragraph>Bullet2.1</Paragraph> 
        <List> 
         <ListItem> 
          <Paragraph>Punkt 2.1.1</Paragraph> 
         </ListItem> 
        </List> 
       </ListItem> 
      </List> 
     </ListItem> 
    </List> 

    <Paragraph>Regular paragraph 1</Paragraph> 
    <Paragraph>Regular paragraph 2</Paragraph> 

</FlowDocument> 

이제 내 문제는 내가 또한 RTF에 FlowDocument를 변환 할 수 있어야한다는 것입니다 보기 좋게 만드십시오. RTF로 변환 할 때 스타일 트리거가 무시되는 것처럼 보입니다.

나는 RTF로 변환이 방법을 사용 : How to convert FlowDocument to rtf

내 질문은 : 일반 단락과을 listitem의 자식 인 단락에 대해 서로 다른 여백을 설정하는 다른 방법이 있나요? 이 문제를 일반적인 스타일을 사용하여 해결해야하며 단락에 스타일 또는 여백 속성을 직접 설정하지 않아야합니다.

답변

2

나는 스스로 이것을 할 수있는 방법을 발견했다.

<Style TargetType="Paragraph"> 
    <Setter Property="Margin" Value="0,0,0,20" /> 
</Style> 

<Style TargetType="ListItem"> 
    <Style.Resources>    
     <Style TargetType="Paragraph"> 
      <Setter Property="Margin" Value="0,0,0,5" /> 
     </Style> 
    </Style.Resources> 
</Style> 

<Style TargetType="{x:Type List}"> 
    <Setter Property="Margin" Value="5" /> 
</Style> 

이것은 내가 처음에하고 싶었던 정확히 : 다음은 업데이트 FlowDocument.Resources 부분이다. ListItem의 단락은 이제 FlowDocument의 일반 단락과 다르게 스타일이 지정됩니다.

0

FlowDocument는 "실시간"문서입니다. 당신은 그것과 상호 작용할 수 있습니다. RTF가 아니며 정적 프리젠 테이션 파일 형식입니다. 텍스트 범위를 rtf로 저장할 때 트리거가 발생하기 전에 기본적으로 컨트롤의 내부 상태에 대한 스냅 샷을 얻습니다. 그렇다면 단락에 적용한 것과 같은 방식으로 단락을 파생시키고 새 ListParagraph에 스타일을 적용하는 새로운 클래스 ListParagraph를 정의 해 볼 수 있습니다. 이 가격은 단락 대신 코드로 ListParagraphs를 만들거나 RTF로 내보내기 전에 바로 단락을 메모리의 ListParagraph로 바꿔야한다는 것입니다.

관련 문제