4
感謝Leom's answer我能夠在FlowDocumentReader包裝到一個的FlowDocument添加到的StackPanel。如何將多個FlowDocumentReaders添加到StackPanel?
但現在我有兩個問題:
- 似乎只加到第一 FlowDocumentReader,其餘忽略
- 有一個不需要保證金,我無法擺脫的
如何將多個FlowDocumentReader添加到StackPanel而沒有不需要的邊距?
alt text http://www.deviantsart.com/upload/1ndiqqe.png
XAML:
<Window x:Class="TestFlowdoc23432.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="200" Width="300">
<StackPanel Margin="10">
<ContentControl x:Name="MainArea"/>
</StackPanel>
</Window>
代碼背後:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace TestFlowdoc23432
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
StackPanel sp = new StackPanel();
TextBlock tb1 = new TextBlock();
tb1.Text = "first text block";
sp.Children.Add(tb1);
TextBlock tb2 = new TextBlock();
tb2.Text = "second text block";
sp.Children.Add(tb2);
sp.Children.Add(GetFlowDocumentReader("first flow document reader"));
sp.Children.Add(GetFlowDocumentReader("second flow document reader"));
MainArea.Content = sp;
}
FlowDocumentReader GetFlowDocumentReader(string text)
{
FlowDocumentReader fdr = new FlowDocumentReader();
FlowDocument fd = new FlowDocument();
fdr.Document = fd;
fdr.Margin = new Thickness(0);
Paragraph par = new Paragraph();
par.Margin = new Thickness(0);
fd.Blocks.Add(par);
Run r = new Run(text);
par.Inlines.Add(r);
return fdr;
}
}
}
正確對目標,效果很好,謝謝! – 2010-02-18 12:23:15
很高興我能幫到你 – 2010-02-18 12:32:38