Silverlight: Scroll issue with RichTextBox Selection property - silverlight

I have a Grid in silverlight having a lot of different controls.
In the last row of Grid, I have a RichTextBox.
To write something in RichTextBox, first we have to scroll down to that because controls are too much.
Each time we open that Grid, all the controls are initiated with some initial data.
Now there is a problem with this line
this.rtb.Selection.Text = "Initial Text";
What this line do is, it set text into RichTextBox control and also set focus on it, as a result my scroll bar move to the bottom, which is very annoying.
I want this text assigned to it but scroller should stay at top.

Try this:
// create a paragraph
Paragraph prgParagraph = new Paragraph();
// create some text, and add it to the paragraph
Run rnMyText = new Run();
rnMyText.Text = "This is some example text with a ";
prgParagraph.Inlines.Add(rnMyText);
// add the paragraph to the RTB
rbtMyRichTextBox.Blocks.Add(prgParagraph);

Related

Adding text in a richtextbox after adding a graphic

When adding a graphic to the end of some text in a richtextbox. It works great. However, when I begin to add more text, the graphic is overwritten. This is not the desired outcome.
I am using the clipboard method for taking a graphic from resources and pasting it into the richtextbox.
// initiate the horizontal bar file
Image image = Properties.Resources.hoz_line_212x4;
// Put the image on the clipboard
Clipboard.SetImage(image);
//// Paste it into the rich text box.
this.msgsrtbx.Paste();
this.msgsrtbx.SelectionLength = 0;
this.msgsrtbx.ScrollToCaret();
When I come to the next bit of text I want to place in teh richtextbox, the graphic is overwritten. I would like it to still remain in the box.

Silverlight tooltip words are reversed

For some reason the tooltip in silverlight is reversing the text displayed.
Here is the code
// Create the colored rectangle
Rectangle rect = new Rectangle();
// Set the grid row and column
Grid.SetRow(rect, i);
Grid.SetColumn(rect, 0);
// Set the rectangle into the UI
LegendColorGrid.Children.Add(rect);
// Create the tooltip for the item
ToolTip tip = new ToolTip();
tip.Content = contentList[i].UnitLabel;
tip.Placement = System.Windows.Controls.Primitives.PlacementMode.Right;
tip.PlacementTarget = rect;
// Set the tooltip into the UI
ToolTipService.SetToolTip(rect, tip);
For example the tooltip is supposed to read '< -85 °C' but the tooltip shown says 'C° 85- >'
So it appears to be because of a want to make a stack panel flow from right to left instead of the default value of left to right.
I set the flowDirection on the stack panel and it was causing the flow direction of the containing tool tips to basically wack out and do some crazy ass stuff like reversing every single letter and reversing some words but not others. No freaking idea why this is happening but if i set the flow direction to LeftToRight on the grid that is directly inside each wrap panel block the contained contents starts behaving by normal rules again.

How to make a RichTextBox automatically resize horizontally & vertically and make its parent resize as well?

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.

Make WinForms control appear on top of all other controls

I have a WinForm, in which I am hiding all borders and the Control Box. Inside the WinForm I have a RECT() (not a WinForms control) the RECT fills the entire WinForm.
I am trying to add a Label to the WinForm, but I want the label to appear on top of the RECT. The Label appears on the WinForm, but never on top of the RECT. I've tried using the following:
/*App Runs - Label does not show up*/
_label.Text = "This is the label";
_label.BackColor = Color.Cornsilk;
_form.Controls.Add(_label);
_form.Controls.SetChildIndex(_label, 0);
/*App Does Not Run*/
_label.Text = "This is the label";
_label.BackColor = Color.Cornsilk;
_form.Controls.SetChildIndex(_label, 0); //trying to set the index before I add the label to the form
_form.Controls.Add(_label);
/*App Runs - Label does not show up*/
_label.Text = "This is the label";
_label.BackColor = Color.Cornsilk;
_label.BringToFront();
_form.Controls.Add(_label);
/*App Runs - Label does not show up*/
_label.Text = "This is the label";
_label.BackColor = Color.Cornsilk;
_form.Controls.Add(_label);
_label.BringToFront();
As you can see, I've tried a lot of different stuff and nothing is working. I have also tried adding the label after the RECT has been added, to no avail. I am having a similar issue with adding a Background Image (though not the question being asked here). Does anyone know of a more forceful way to make the Label appear on top of the RECT?
Also, because of the API and dll's I am using, I cannot use something other than a RECT or WinForms.
You can use BringToFront on the label itself:
_label.BringToFront();
This will bring the label to the front of the Z order on the form, so it should display on top of other form elements.
I have a RECT() (not a WinFrom control) the RECT fills the entire WinForm
A "RECT" isn't a control - it's a definition size and position. Depending on what you're using to display your background, this may not work. If it's painting into the entire form, it could be overwriting your other controls, and "masking" them, no matter what you use for z order. Without more information, it could be difficult to provide guidance, but you'd have to make sure you cause the label to redraw after the "RECT".

How to hide the border around child window

I have a child Window , and I am displaying it from the code behind as below:
ChildPhotoViewer PhotoViewer = new ChildPhotoViewer();
PhotoViewer.DataContext = selectedPhoto;
PhotoViewer.Title = selectedPhoto.strTitle.ToString();
PhotoViewer.Show();
But While Displaying the child window I am getting the Close Button and a Border thickness arround the Window.
I am able to hide the Close Button but is there a way to hide the thickness(Border) across the child window.
Edit:
![alt text][1]
In the Image , there is border arround image after Collpasing the Close button and making
PhotoViewer.Title = null;
PhotoViewer.HasCloseButton = false;
I want to get rid of that Rectangular Border.
Have you tried:-
PhotoViewer.BorderThickness = new Thickness(0);
Edit
Perhaps you are refering to the title block across the top of the window?
PhotoViewer.Title = null;
PhotoViewer.HasCloseButton = false;
Edit
Third attempt.
The template for ChildWindow place the content in border with a 7 pixel margin. This also has an outer border which has a White background. That is what you are seeing in the image. The only way to eliminate it is to copy the ChildWindow template and edit it.
Depends on what you mean by the Border.
If you have a look at the Documentation you can see there is a border (with a thickness of 1) around the edge of the entire window that can be altered like Anthony mentions.
However there is also the window Chrome which in the default template has a number of borders. To change the thickness of these borders you will need to create a style without the borders being present.

Resources