We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

[UWP] Programm Scrolling in sfRichTextBoxAdv

Hi there! I recently started using your library.
I was most interested in sfRichTextBoxAdv, and I began to "dig" it.
Is it possible to get/set from the code scroll value for him?
Any ideas?

3 Replies

VM Venkatesan Mani Syncfusion Team June 16, 2017 10:20 AM UTC

Hi Democraten,

Thank you for using Syncfusion products.

At present our SfRichTextBoxAdv control does not have API support to perform scrolling. We have already logged this requirement as feature request. We will implement these features in any of our forthcoming releases. We usually have a timeframe of at least three months between releases. The feature implementation would also greatly depend on the factors like product design, code compatibility and complexity. We request you to visit our website periodically for feature related updates.

Now, as a workaround you can achieve your requirement by writing an extension class for SfRichTextBoxAdv. In that class, you can get the vertical and horizontal scroll bars from the template and then by manipulating it values you can scroll from code behind. We have prepared a sample to demonstrate the same. Please find the sample code and sample below,

Code of Extension class:
C#: 
/// <summary> 
/// Represents the extension class for SfRichTextBoxAdv. 
/// </summary> 
public class SfRichTextBoxAdvExtension : SfRichTextBoxAdv 
{ 
    #region Fields 
    ScrollBar verticalScrollBar; 
    ScrollBar horizontalScrollBar; 
    #endregion 
 
    #region Properties 
    /// <summary> 
    /// Gets or sets the verical scrollbar value. 
    /// </summary> 
    public double VScrollValue 
    { 
        get 
        { 
            if (verticalScrollBar != null) 
                return verticalScrollBar.Value; 
            return 0; 
        } 
        set 
        { 
            if (verticalScrollBar != null) 
                verticalScrollBar.Value = value; 
        } 
    } 
    /// <summary> 
    /// Gets or sets the horizontal scrollbar value. 
    /// </summary> 
    public double HScrollValue 
    { 
        get 
        { 
            if (horizontalScrollBar != null) 
                return horizontalScrollBar.Value; 
            return 0; 
        } 
        set 
        { 
            if (horizontalScrollBar != null) 
                horizontalScrollBar.Value = value; 
        } 
    } 
    /// <summary> 
    /// Gets the vertical scroll bar maximum value. 
    /// </summary> 
    public double VScrollMaxValue 
    { 
        get 
        { 
            if (verticalScrollBar != null) 
                return verticalScrollBar.Maximum; 
            return 0; 
        } 
    } 
    /// <summary> 
    /// Gets the horizontal scroll bar maximum value. 
    /// </summary> 
    public double HScrollMaxvalue 
    { 
        get 
        { 
            if (horizontalScrollBar != null) 
                return horizontalScrollBar.Maximum; 
            return 0; 
        } 
    } 
    #endregion 
 
    #region Constructor 
    /// <summary> 
    /// Initializes the instance of SfRichTextBoxAdvExtension class. 
    /// </summary> 
    public SfRichTextBoxAdvExtension() 
    { 
        // Wires the Loaded event. 
        this.Loaded += SfRichTextBoxAdvExtension_Loaded; 
    } 
 
    #endregion 
 
    #region Events 
    /// <summary> 
    /// Called when SfRichTextBoxAdv is loaded. 
    /// </summary> 
    /// <param name="sender"></param> 
    /// <param name="e"></param> 
    private void SfRichTextBoxAdvExtension_Loaded(object sender, RoutedEventArgs e) 
    { 
        verticalScrollBar = GetTemplateChild("VerticalScrollBar") as ScrollBar; 
        horizontalScrollBar = GetTemplateChild("HorizontalScrollBar") as ScrollBar; 
    } 
    #endregion 
 
    #region Implementation 
    /// <summary> 
    /// Do the vertical scroll. 
    /// </summary> 
    /// <param name="deltaValue"></param> 
    public void DoVerticalScroll(double deltaValue) 
    { 
        if (deltaValue != 0 && verticalScrollBar != null) 
        { 
            double previousValue = VScrollValue; 
            if (previousValue + deltaValue <= VScrollMaxValue) 
                VScrollValue = previousValue + deltaValue; 
            else 
                VScrollValue = VScrollMaxValue; 
        } 
    } 
    /// <summary> 
    /// Do the horizontal scroll 
    /// </summary> 
    /// <param name="deltaValue"></param> 
    public void DoHorizontalScroll(double deltaValue) 
    { 
        if (deltaValue != 0 && horizontalScrollBar != null) 
        { 
            double previousValue = HScrollValue; 
            if (previousValue + deltaValue <= HScrollMaxvalue) 
                HScrollValue = previousValue + deltaValue; 
            else 
                HScrollValue = HScrollMaxvalue; 
        } 
    } 
    /// <summary> 
    /// Disposes the instance. 
    /// </summary> 
    public void Dispose() 
    { 
        verticalScrollBar = null; 
        horizontalScrollBar = null; 
        this.Loaded -= SfRichTextBoxAdvExtension_Loaded; 
        base.Dispose(); 
    } 
    #endregion 
} 

Sample :
http://www.syncfusion.com/downloads/support/forum/130995/ze/Sample_ScrollProgramattically1039990903

Please try the running sample and let us know if this helps you.

Regards,
Venkatesan M. 



DE Democraten June 16, 2017 12:55 PM UTC

Venkatesan M,Thank you very much, excellent answer! It's works. To be honest, at first I wanted to do something like that, but it seemed to me that there is a simpler way. However, it works. Thank you for finding the time and provided the whole project. The question is closed.


VM Venkatesan Mani Syncfusion Team June 19, 2017 04:31 AM UTC

Hi Democraten,

Thank you for your update.

Please let us know if you require any further assistance. We will be happy to assist you.

Regards,
Venkatesan M.  


Loader.
Live Chat Icon For mobile
Up arrow icon