removed lazy evaluation of the ScrollViewer property.

This commit is contained in:
morkt 2015-05-13 23:24:50 +04:00
parent 66ba1c5ccf
commit f7b3fa522c

View File

@ -39,12 +39,10 @@ namespace JustView
/// </summary> /// </summary>
public partial class TextViewer : FlowDocumentScrollViewer public partial class TextViewer : FlowDocumentScrollViewer
{ {
Lazy<ScrollViewer> m_scroll_viewer;
Lazy<double> m_default_width; Lazy<double> m_default_width;
public TextViewer () public TextViewer ()
{ {
m_scroll_viewer = new Lazy<ScrollViewer> (FindScrollViewer);
m_default_width = new Lazy<double> (() => GetFixedWidth (80)); m_default_width = new Lazy<double> (() => GetFixedWidth (80));
InitializeComponent(); InitializeComponent();
DefaultZoom = 100; DefaultZoom = 100;
@ -56,7 +54,7 @@ namespace JustView
Input = null; Input = null;
} }
public ScrollViewer ScrollViewer { get { return m_scroll_viewer.Value; } } public ScrollViewer ScrollViewer { get { return FindScrollViewer(); } }
public double DefaultWidth { get { return m_default_width.Value; } } public double DefaultWidth { get { return m_default_width.Value; } }
public double DefaultZoom { get; private set; } public double DefaultZoom { get; private set; }
public Stream Input { get; set; } public Stream Input { get; set; }
@ -69,6 +67,7 @@ namespace JustView
set set
{ {
m_word_wrap = value; m_word_wrap = value;
if (Input != null)
ApplyWordWrap (value); ApplyWordWrap (value);
} }
} }
@ -188,11 +187,9 @@ namespace JustView
} }
public void ApplyWordWrap (bool word_wrap) public void ApplyWordWrap (bool word_wrap)
{
if (word_wrap)
{ {
var scroll = this.ScrollViewer; var scroll = this.ScrollViewer;
if (scroll != null) if (word_wrap && scroll != null)
{ {
this.Document.PageWidth = scroll.ViewportWidth; this.Document.PageWidth = scroll.ViewportWidth;
var width_binding = new Binding ("ViewportWidth"); var width_binding = new Binding ("ViewportWidth");
@ -202,19 +199,13 @@ namespace JustView
BindingOperations.SetBinding (this.Document, FlowDocument.PageWidthProperty, width_binding); BindingOperations.SetBinding (this.Document, FlowDocument.PageWidthProperty, width_binding);
} }
else else
{
BindingOperations.ClearBinding (this.Document, FlowDocument.PageWidthProperty);
this.Document.PageWidth = this.ActualWidth;
}
}
else
{ {
BindingOperations.ClearBinding (this.Document, FlowDocument.PageWidthProperty); BindingOperations.ClearBinding (this.Document, FlowDocument.PageWidthProperty);
this.Document.PageWidth = MaxLineWidth; this.Document.PageWidth = MaxLineWidth;
} }
} }
public ScrollViewer FindScrollViewer () private ScrollViewer FindScrollViewer ()
{ {
if (VisualTreeHelper.GetChildrenCount (this) == 0) if (VisualTreeHelper.GetChildrenCount (this) == 0)
return null; return null;