I provided an answer to a question about setting the focus to a specific control using Caliburns IResult
here. You should be able to use the same concept to get hold of the RichTextBox
in order to invoke ScrollToEnd
. I will not duplicate the entire explanation here, go to that question for the ideas, but the following IResult
implementation (as a guide) should put you on the right track.
public class RichTextBoxScrollToEnd : ResultBase
{
public RichTextBoxScrollToEnd()
{
}
public override void Execute(ActionExecutionContext context)
{
var view = context.View as UserControl;
List<Control> richTextBoxes =
view.GetChildrenByType<Control>(c => c is RichTextBox);
var richTextBox = richTextBoxes.FirstOrDefault();
if (richTextBox != null)
richTextBox.Dispatcher.BeginInvoke(() =>
{
richTextBox.ScrollToEnd();
});
RaiseCompletedEvent();
}
}
If you have multiple RichTextBoxes
in your view you could provide a parameter to the constructor of RichTextBoxScrollToEnd
which is the name of the specific control you want to target and then filter richTextBoxes using that name i.e.
var richTextBox = richTextBoxes.FirstOrDefault(c => c.Name == _nameOfControl);
See the referenced question for more details though.