0
我正在使用DocumentFlowReader顯示txt文件中的文本。一切工作正常,但是當我全屏顯示我的文本分成幾列時,如何僅在一個列中顯示它?如何使用C#中的DocumentFlowReader在一列中顯示簡單的txt文件中的文本WPF
這裏是我的代碼:
XAML文件:
<DockPanel>
<Menu DockPanel.Dock="Top">
<MenuItem Header="_File">
<MenuItem x:Name="OpenFile" Header="_Open" Click="OpenFile_Click" />
<Separator />
<MenuItem Header="_Exit" />
</MenuItem>
</Menu>
<TextBlock x:Name="txtCurrentPage" DockPanel.Dock="Bottom" TextAlignment="Center" Background="LightYellow">
Current page:
</TextBlock>
<DockPanel DockPanel.Dock="Left">
<TextBlock DockPanel.Dock="Top">Your books</TextBlock>
<ListView DockPanel.Dock="Left" x:Name="listboxBooks" Grid.Row="1" BorderThickness="0" ItemsSource="{Binding}" PreviewMouseDoubleClick="listboxBooks_PreviewMouseDoubleClick">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" Width="120" DisplayMemberBinding="{Binding name}" />
<GridViewColumn Header="Finished" Width="120" DisplayMemberBinding="{Binding readBook}" />
</GridView>
</ListView.View>
</ListView>
</DockPanel>
<TextBlock DockPanel.Dock="Right" Background="Bisque">
<Button x:Name="btnPreviousPage" Click="btnPreviousPage_Click" >Previous Page</Button>
<Button x:Name="btnNextPage" Click="btnNextPage_Click">Next Page</Button>
<Button x:Name="btnSavePage" Click="btnSavePage_Click" >Save Page</Button>
</TextBlock>
<FlowDocumentReader Name="FlowDocReader" Background="LightBlue">
</FlowDocumentReader>
</DockPanel>
這是我如何讀取文件中的文本:
// Create OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".txt";
dlg.Filter = "Text Files (*.txt)|*.txt";
string filename = dlg.FileName;
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(System.IO.File.ReadAllText(filename));
FlowDocument document = new FlowDocument(paragraph);
FlowDocReader.Document = document;
此代碼做的不錯,它正在讀數據並顯示它,但是當窗口全屏時,它會在幾列中顯示文本。即使在窗口全屏的情況下,我也只想顯示它。我怎樣才能做到這一點?