RichTextBox doesn't scroll on mouse wheel - c#

I have UserControl in SL4 project with a richtextbox with big amount of text in it. Problem that mouse scrolling doesn't work in it. While I dragging scroll bar - that works and when I press arrows on keyboard - scroll is working too, but when I am trying to use mouse wheel for scrolling - it doesnt work at all.
I've reduced this control to simplest:
<UserControl x:Class="CTermsOfUsePage"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="900">
<RichTextBox Height="400">
<Paragraph>
Big amount of text with many LineBreaks here.
</Paragraph>
</RichTextBox>
</UserControl>
But the scroll still doesn't work. I've tried to create a new SL application with such code - all is working fine there. I've also checked default styles - there is no style for RichTextBox.
Are there any suggestion - what can be a problem's source?
Update: problem occur in Chrome/FF/Opera in IE9 scroll is working fine.

We've found problem source. In project's .aspx file in <div id="silverlightControlHost"> section we have a setting <param name="windowless" value="true" />. When this parameter has been set to false all worked fine.
As well as in IE "true" settings works fine it looks like SL bug.

Related

WPF ScrollViewer for ListBox -> Performance issues

I'm trying to create grid with listbox with Scrollbar.
It's done somehow like that:
<Grid>
<ListBox Name="xxx" ItemsSource="{Binding}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible">
....
</ListBox>
</Grid>
The problem is that if I use scrollbar, then the size of bar-button jumps back and forward within scrolling. If I remove ScrollViewer from properties and instead put ListBox in ScrollViewer tag, then everything is working perfect, except of terrible performance of rerendering UI (resize, move window, resource consuming). According to google it does "disable virtualization". This sounds crazy that there's no simple solution to get properly working scrollbar and usable UI without issues.
Is there compromise for both of these things? Virtualization + properly working scrollviewer with fixed size of scrollbar button.

Moving Control over a ScrollViewer

I'm developing a small WPF application which uses a ScrollViewer to show an Image in a Window.
I have generated the window and all his relative code (I will show it if needed but I think is not usefull for the point of this question) programmatically.
The question/ how to is the following. I have to show/hide (pressing a button) a control (basically a InkCanvas) over the image contained in the ScrollViewer. Except the part oh show/hide is pretty simple to use the button event) which is the best way to add a control (and which type of control/container) at the Window forcing him to be over the ScrollViewer and then be able to move around dragging it?
I'm relatively new to WPF I used a lot of WinForms (I can do this in WinForms but WPF is a new world for me).
Thanks in advance!
As for the container you should use a Grid which will center and put on top of each other the controls in a same cell.
As for drag and drop if you want to implement it yourself I've provided a minimal implementation here: https://stackoverflow.com/a/17014906/145757
Otherwise you can use the MouseDragElementBehavior behavior provided by Blend.
Here is a tutorial that demonstrates its usage from Blend itself: http://www.c-sharpcorner.com/uploadfile/nipuntomar/expression-blend-4-behaviors/
But you can use it without Blend by importing the Blend libraries and using it from your XAML with something like:
<InkCanvas ...>
<interactivity:Interaction.Behaviors>
<blendbehaviors:MouseDragElementBehavior />
</interactivity:Interaction.Behaviors>
</InkCanvas>
with interactivity and blendbehaviors being mapped to the Blend namespaces.

Why does my control extending RichTextBox defaults to gray background?

I'm attempting to extend a RichTextBox, so as to add some extra functionality; however, I'm running into a strange issue with the background color of my extended RTB. Here is the code:
RichTextBoxExtended.cs
public class RichTextBoxExtended: RichTextBox
{
// completely empty
}
MyView.xaml
<UserControl x:Class="MyNamespace.MyView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<RichTextBoxExtended />
</Grid>
</UserControl>
However, when showing this in a WPF page, the background color of the text box is gray, as if it were disabled (which it isn't, since I can still type into it fine). As a test, I replaced <RichTextBoxExtended /> in the XAML with <RichTextBox />, and that control is white as expected.
Does anyone know what could cause this issue? I can easily work around the problem by manually setting the background color to white, but am looking for a better solution.
I just copy paste your code to a test solution, place a frame in main window and put the RichTextBoxExtended in a page inside the frame, but the background of RTB is completely white. I think there is something else causing the problem.

How to display wait cursor when focusing on a RTB in WPF

So what is happening right now is the following. When I am focusing on a rich text box in my WPF application, I can't seem to change the cursor from a Carat (or what ever the 'I' text selection cursor is).
This is a problem, because when the user hits Ctrl+S, I want the program to save, and I want to display the Cursor.Wait cursor. This works if I am focusing on any other control (Treeview, stackPanel, Menu), everything except the RTB.
Is it just built this way with no way around it?
FrameworkElement.ForceCursor Property set to True will override the cursor preferences established by child elements:
<StackPanel ForceCursor="True" Cursor="Wait">
<RichTextBox />
</StackPanel>
Now RichTextBox will show StackPanel cursor.

Place WPF Popup Along Bottom of Screen

I have a Popup that consists of a grid of labels. The popup sits inside a Canvas like this.
<Canvas x:Name="mainCanvas">
<Popup x:Name="mainPopup"
IsOpen="True"
PlacementTarget="{Binding ElementName=mainCanvas}"
PopupAnimation="Fade"
AllowsTransparency="True"
Placement="Center">
Wrapping inside the canvas (or similar control) is the only way I've found to allow the popup's contents to be transparent.
Anyway, all of this works fine and I see my grid of labels across the center of the screen. What I'd really want though is to display the grid of labels across the bottom of the screen. However when I change Placement="Center" to Placement="Bottom", I don't see the popup at all.
Have you seen this? It is a pretty good explanation about how popup placement works.
I created a test WPF project in Blend and pasted your exact code, then changed Placement to Bottom. I did see the content I added to the popup (a TextBlock with some junk text), but it was hard to see, since it is positioned below mainCanvas (as expected).
So... there must be some other problem aside from the code you showed.

Categories