2

I am using RichEditBox to allow user to enter text (C# Windows 8) I am also allowing repositioning of the RichEditBox on the screen But with the touch screen and finger the text is scrolled instead of repositioning the control If mouse is used, the RichEditBox gets repositioned on the screen

I was trying to disable the text scroll in RichEditBox to eliminate this problem. Tried with

ScrollViewer.VerticalScrollModeProperty = ScrollBarVisibility.Disabled;

gives error: Property or indexer 'Windows.UI.Xaml.Controls.ScrollViewer.VerticalScrollModeProperty' cannot be assigned to -- it is read only

Is there any way to disable the text scrolling in RichEditBox or any other way to solve this problem?

ashish nirkhe
  • 689
  • 3
  • 10
  • 22

2 Answers2

0

You've got two problems:

  1. You're trying to set VerticalScrollModeProperty to something that doesn't change the scroll mode - "ScrollBarVisibility.Disabled" changes the scrollbar's visibility, but it doesn't disable scrolling. Instead, you'll want to use "ScrollMode.Disabled".

  2. VerticalScrollModeProperty is a property which can only be retrieved with a getter (element.getValue(...)), and changed with a setter (element.setValue(...)). Some properties require you to do this instead of accessing them directly (which is what you were trying to do with the syntax ScrollViewer.VerticalScrollModeProperty = someValue). In the future, if you get the error you got above, chances are your next step is to try using getValue() and setValue() for that property instead.

So! If you want to disable vertical scrolling on the C# side of things (as you were trying to do above), use this:

editBoxName.setValue(VerticalScrollModeProperty, ScrollMode.Disabled);

If you're in the stylesheet (like StandardStyles.xaml) and want to set this property there instead of doing so programmatically (say you want multiple RichEditBox elements with scrolling disabled), try this:

<Style x:Key="styleName" TargetType="RichEditBox">
    <Setter Property="ScrollViewer.VerticalScrollMode" Value="Disabled" />
    <!-- your other RichEditBox properties can go here, if you'd like -->
</Style>

Final note - if you go the stylesheet route, to to get your RichEditBox correctly using that style ("styleName"), you'll want to do the following in the XAML where you instantiate your RichEditBox:

<RichEditBox x:Name="myEditBox" Style="{StaticResource ResourceKey=styleName}" />
0

Got it working with disabling the scrollviewer modes instead of properties:

<RichEditBox AcceptsReturn="True" IsSpellCheckEnabled="True" 
                         ScrollViewer.VerticalScrollMode="Disabled"
                         ScrollViewer.HorizontalScrollMode="Disabled"
                         TextWrapping="Wrap" IsTapEnabled="True" IsHoldingEnabled="True"
                         IsDoubleTapEnabled="True" IsRightTapEnabled="True"
                         IsReadOnly="False" Height="{Binding Height}" 
                         Width="{Binding Width}" TextAlignment="{Binding TextAlignment}"
                         FontFamily="{Binding FontFamily}" FontSize="{Binding FontSize}"
                         ManipulationMode="All" GotFocus="TextItem_GotFocus" KeyDown="TextItem_KeyDown"                             
                         ManipulationDelta="EditBox_ManipulationDelta"/>
ashish nirkhe
  • 689
  • 3
  • 10
  • 22