How to check whether the caretposition is inside the visible region of a window.
I am using Richtextbox inside a Scrollviewer.Whenever the cursor moves to the non-visible area of Richtextbox I need to call the scrollviewer's line down.
Not sure, but could you just set the RichTextBox.VerticalScrollBarVisibility, instead of putting your RichTextBox in a ScrollViewer?
Related
I need to put a RichTextBox inside a container such as a canvas/grid/stackpanel or anything which serves the purpose best.
look at the example I made:
in the picture RichTextBox is white, Canvas is LightBlue, and the main window's Grid is salmon(=light orange)
The user starts typing inside the RichTextBox. as far as he DOESN'T press enter or shift+enter, the RichTextBox must resize horizontally as long as the sentence is, on the condition that it doesn't exceed the main grid's boundaries.
RichTextBox must also resize vertically, when the user starts typing in new lines, but should not exceed the grid's boundaries.
So how is it done ?
This is not the best aproach that you looking for but i't works...
Just increase the Document.PageWidth based on the content inside the textbox by doing this
richTextBox1.Document.PageWidth = 1000;
However, consider looking for No Wrap for the richtext box. Wich i'm out of time to give more help.
I'm trying to implement panning within a Canvas within a scrollviewer like:
<ScrollViewer>
<Canvas>
<!-- some visual elements here -->
</Canvas>
</ScrollViewer>
I want a click and drag operation within the canvas to cause the contents of the canvas to move. I've tried handling the MouseDown, MouseMove, and MouseUp events to do a translation in the manner described here but it hasn't worked.
Any ideas?
You can't do that with your current setup. A Canvas will stretch beyond its parent container and the scrollviewer won't know the size of the Canvas (it will tell it it doesn't need to scroll) and therefore can't create the handles.
If you want to skip with that set up change the canvas to a grid and use the Vertical Scroll and Horizontal Scroll and associated set properties to move the visible section of the grid around.
Try giving your Canvas a set Width and Height and give it a background color (Transparent should be fine) and see if that helps you get your mouse events.
I have a wpf window, and there is a footer sections that can have multiple content which makes the width of the footer grows.
I set SizeToContent="WidthAndHeight" in my Window and when I add a lot of content to ScrollViewer, it grows accordingly, instead of just show the scrollbar.
It looks like ScrollViewer is taking into account its content, so how do I set the ScrollViewer to ignore it's content and only take the width available instead of make it grow?
thanks!
I suspect that by setting SizeToContent="WidthAndHeight" you tell the controls inside the window that they "can have all the space they want", so the ScrollViewer does not do anything becase it is not being restricted by its parent which is a necessary condition for a ScrollViewer to work (and make sense).
Try setting the MaxWidth property of the ScrollViewer. Once it has reached this width, it should start showing scrollbars.
I have a question regarding the setting of the HorizontalOffset-property (using the ScrollToHorizontalOffset method).
Upon starting my application, the content for the scrollviewer is dynamically created (i.e. I do not know its extent during design-time). I then want to set the horizontal offset of the scrollviewer control, however at that time its scrollable width is returned as 0. Calling UpdateLayout on the scrollviewer does not help either.
I am currently working around this issue by checking the ScrollableWidth property of the scrollviewer control in the rendering event and make a call to ScrollToHorizontalOffset as soon as ScrollableWidth > 0.
This works fine but leads to a short display of the wrong inital position, before in "rendering" the position is adjusted.
Is there anything I can do to force an update on the scrollviewer so that I can set its horizontal offset without this hassle?
Thanks in advance!
Set the opacity of the Content control in the scroll viewer to 0. When you've called ScrollToHorizontalOffset then set the content control's opacity to 1. That way no content is actually seen until its positioned correctly.
Scrollable Height/Width will be zero until the child content is loaded. Until then, it doesn't know how big it needs to be - thus the value of 0.
I have an ItemsControl in a ScrollViewer. The items in the ItemsControl are expanded to a DataTemplate which basically consists of an Adorner.
Now the problem is, when scrolling, the Visual Children of the Adorner are visible outside the ScrollViewer. Lets say I scroll from the Horizontal Offset 0 to 100, the Visual Children of the Adorner move to the left and are visible next to the ScrollViewer, although they should be hidden. Setting ClipToBounds on the ItemsControl or the ScrollViewer does not work.
I understand, that Adorner are rendered above all elements z-order wise, but they really shouldn't be visible in such cases as with the ScrollViewer. The adorned Element by the way behaves like expected and is not visible through the ScrollViewer.
Is there any easy way to "clip" the Adorners, so that they are only visible in the visible scroll area?
Thanks,
Andrej
Setting ClipToBounds on the containing control is not enough. You must set the adorner's IsClipEnabled property too.
I've encountered the same problem when subclassing the WPFToolkit DataGrid to draw an adorner around the current cell.
The content of the ScrollViewer is rendered by a ScrollContentPresenter instance. ScrollContentPresenter has its own adorner layer, which is accessible through the ScrollContentPresenter.AdornerLayer property.
I found that my adorner correctly clips if I add it to that layer.
My solution was to push a clip region onto the drawing context, render whatever I needed, and pop the clipping at the end, like this:
drawingContext.PushClip(new RectangleGeometry(new Rect(0, 0, this.AdornedElement.RenderSize.Width, this.AdornedElement.RenderSize.Height)));
// continue drawing
drawingContext.Pop();
You can plug this in into any Adorner, the bounds are already available as part of the element.