SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

AvalonEdit: Scroll Bars

Last post 02-28-2010 3:17 PM by DanielGrunwald. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 02-28-2010 12:41 PM

    AvalonEdit: Scroll Bars

    Hi,

    I just downloaded and built the AvalonEdit control, I was just wondering if you can remove the scroll bars from the control?  I only need a small text area but with syntax highlighting and code completion.

    Is it also possible to bind to the text property so I can use this control in a MVVM code layout?

    Thanks,

  • 02-28-2010 1:14 PM In reply to

    Re: AvalonEdit: Scroll Bars

    Never mind about the scroll bar part, I worked that one out:

                <avalonedit:TextEditor.Template>

                    <ControlTemplate>

                        <ScrollViewer

    Focusable="False"

    Name="PART_ScrollViewer"

    CanContentScroll="False"

    VerticalScrollBarVisibility="Hidden"

    HorizontalScrollBarVisibility="Hidden"

    Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TextArea}"

    VerticalContentAlignment="Top"

    HorizontalContentAlignment="Left"

    Background="{TemplateBinding Background}"

    Padding="{TemplateBinding Padding}"

    />

                    </ControlTemplate>

                </avalonedit:TextEditor.Template>

     

    I'm still interested about the MVVM binding pattern question?

     

  • 02-28-2010 2:13 PM In reply to

    Re: AvalonEdit: Scroll Bars

    Binding to the Text property is not possible.

    Unfortunately I don't know any way to efficiently implement data binding. The editor has to inform data binding whenever the value changes, but creating a string instance for the whole document content on every key press would be too slow for large documents.

    The WPF TextBox solves this problem by using System.Windows.DeferredReference to create the string instance only when the data binding system needs to read the value - but the DeferredReference class is internal and cannot be used by anyone but Microsoft.

    There are two possible workarounds:

    1. Bind to the TextEditor.Document property (keep a TextDocument instead of a string in your view model)

    2. Derive from TextEditor and add a bindable Text property, using event handlers to synchronize between your property and base.Text. You'll get the performance hit of creating the string instance on every change, but that won't be a problem if you don't need to edit large files.

  • 02-28-2010 2:40 PM In reply to

    Re: AvalonEdit: Scroll Bars

    Thanks for the fast reply, I guessed as much.

    I have tried what you said using the TextDocument binding like this(in ViewModel)

            TextDocument textdoc = new TextDocument();
            public TextDocument FinalSQLString
            {
                get
                {
                    textdoc.Text = this.fromexpression.ToBLOCKED EXPRESSION;
                    return textdoc;
                }

            }

    and binding

                    <avalonedit:TextEditor FontFamily="Consolas" 
                                       Name="finalblock" 
                                       WordWrap="True"
                                       Document="{Binding FinalSQLString}">
                    </avalonedit:TextEditor>

     

    but I'm getting this 'Object reference not set to an instance of an object.'

    StackTrace:

       at ICSharpCode.AvalonEdit.Editing.Caret.BringCaretToView(Double border) in C:\Users\Woo\Desktop\SharpDevelop\src\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\Editing\Caret.cs:line 371

       at ICSharpCode.AvalonEdit.Editing.SelectionMouseHandler.ExtendSelectionToMouse(MouseEventArgs e) in C:\Users\Woo\Desktop\SharpDevelop\src\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\Editing\SelectionMouseHandler.cs:line 561

       at ICSharpCode.AvalonEdit.Editing.SelectionMouseHandler.textArea_MouseMove(Object sender, MouseEventArgs e) in C:\Users\Woo\Desktop\SharpDevelop\src\Libraries\AvalonEdit\ICSharpCode.AvalonEdit\Editing\SelectionMouseHandler.cs:line 505

       at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)

       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)

       at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)

       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)

       at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)

       at System.Windows.Input.InputManager.ProcessStagingArea()

       at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)

       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)

       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)

       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)

       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)

       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)

       at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)

       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)

       at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)

       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)

       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)

       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)

       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)

       at System.Windows.Threading.Dispatcher.Run()

       at System.Windows.Application.RunDispatcher(Object ignore)

       at System.Windows.Application.RunInternal(Window window)

       at System.Windows.Application.Run(Window window)

       at System.Windows.Application.Run()

       at SQLBuilderWPF.App.Main() in C:\Users\Woo\documents\visual studio 2010\Projects\SQLBuilderWPF\SQLBuilderWPF\obj\x86\Release\App.g.cs:line 0

       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[ args)

       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[ args)

       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

       at System.Threading.ThreadHelper.ThreadStart()

     

     

  • 02-28-2010 3:13 PM In reply to

    Re: AvalonEdit: Scroll Bars

    I found out what the problem was, I am using UpdateControls to help with MVVM and it was wrapping my VM at runtime and was having conversion issues when binding.

  • 02-28-2010 3:17 PM In reply to

    Re: AvalonEdit: Scroll Bars

     

    The only way I can see that exception happening with the current version is if you set TextEditor.Document to null and then click into the blank editor window. I've fixed that in revision 5559.

Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.