title: WPF FlowDocument - style paragraphs in listitems
body: <p>I am trying to style a FlowDocument to make it behave the same way as when entering text in MS Word. Right now, I am stuck with paragraph margins within a listitem. I have made it look just about the way I want to:</p>
  
  <p><img src="https://i.stack.imgur.com/WIoN3.png" alt="FlowDocument preview"></p>
  
  <p>using this XAML:</p>
  
  <pre><code>&lt;FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;FlowDocument.Resources&gt;
  
          &lt;Style TargetType="Paragraph"&gt;
              &lt;Setter Property="Margin" Value="0,0,0,20" /&gt;
              &lt;Style.Triggers&gt;
                  &lt;DataTrigger Binding="{Binding Margin, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListItem}, AncestorLevel=1}}" Value="0"&gt;
                      &lt;Setter Property="Margin" Value="5" /&gt;
                  &lt;/DataTrigger&gt;
              &lt;/Style.Triggers&gt;
          &lt;/Style&gt;
  
          &lt;Style TargetType="{x:Type List}"&gt;
              &lt;Setter Property="Margin" Value="5" /&gt;
          &lt;/Style&gt;
  
      &lt;/FlowDocument.Resources&gt;
  
      &lt;List&gt;
          &lt;ListItem&gt;
              &lt;Paragraph&gt;Bullet1&lt;/Paragraph&gt;
          &lt;/ListItem&gt;
          &lt;ListItem&gt;
              &lt;Paragraph&gt;Bullet2&lt;/Paragraph&gt;
              &lt;List&gt;
                  &lt;ListItem&gt;
                      &lt;Paragraph&gt;Bullet2.1&lt;/Paragraph&gt;
                      &lt;List&gt;
                          &lt;ListItem&gt;
                              &lt;Paragraph&gt;Punkt 2.1.1&lt;/Paragraph&gt;
                          &lt;/ListItem&gt;
                      &lt;/List&gt;
                  &lt;/ListItem&gt;
              &lt;/List&gt;
          &lt;/ListItem&gt;
      &lt;/List&gt;
  
      &lt;Paragraph&gt;Regular paragraph 1&lt;/Paragraph&gt;
      &lt;Paragraph&gt;Regular paragraph 2&lt;/Paragraph&gt;
  
  &lt;/FlowDocument&gt;
  </code></pre>
  
  <p>My problem now is that I also need to be able to convert the FlowDocument to RTF and make it look good. When converting to RTF, it seems like the the style triggers are ignored. </p>
  
  <p>I use this method to convert to RTF:
  <a href="https://stackoverflow.com/questions/829053/how-to-convert-flowdocument-to-rtf">How to convert FlowDocument to rtf </a></p>
  
  <p>My question is:
  Is there any other way to set different margins for a regular paragraph and a paragraph that is child of a listitem? I need to solve this using general styles, and NOT by setting the Style or Margin attribute directly on the paragraphs.</p>