This is an attempt to implement a read-only Linux text file (one byte newline sequence) viewer for Windows.
It presently has a ScrollViewer that will not resize when the WPF MainWindow is resized. How do I make the ScrollViewer size subservient to the MainWindow?
private void ScrollViewer1GotFocus(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg =
new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document";
dlg.DefaultExt = ".txt";
dlg.Filter = null;
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
string filename = dlg.FileName;
StreamReader streamReader = new StreamReader(filename,
System.Text.Encoding.ASCII);
string text = streamReader.ReadToEnd();
FlowDocument flowDocument = new FlowDocument();
flowDocument.TextAlignment = TextAlignment.Left;
flowDocument.FontFamily = new FontFamily("Lucida Console");
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add(text);
flowDocument.Blocks.Add(paragraph);
FlowDocumentScrollViewer fdsv = new FlowDocumentScrollViewer();
fdsv.Document = flowDocument;
ScrollViewer1.Content = fdsv;
}
}
private void MainWindow1SizeChanged(object sender, SizeChangedEventArgs e)
{
}
The XAML:
<Window x:Name="MainWindow1" x:Class="ReadOnlyViewLinux1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ReadOnlyView" Height="256" Width="512" SizeChanged="MainWindow1SizeChanged">
<ScrollViewer x:Name="ScrollViewer1" HorizontalAlignment="Left" Height="236" Margin="10,10,0,-21" VerticalAlignment="Top" Width="492" GotFocus="ScrollViewer1GotFocus"/>