Search code examples
silverlightrichtextboxfullscreenrich-text-editorsilverlight-oob

Fullscreen richtextbox in silverlight


I have a dataform with a richtextbox In it. The user can type some text and have some editing capability, but I'd like to give the user the option to expand the editor to fullscreen to have more richtextbox editing options. How can I implement a function that will allow me to fullscreen (or atleast create a bigger window) the richtexteditor so the user has better overview over the document and more editing options?

This is ment to be possible in OOB mode.


Solution

  • Full screen wont work as you have limit keyboard input in fullscreen:

    • Up Arrow
    • Down Arrow
    • Left Arrow
    • Right Arrow
    • Spacebar
    • Tab
    • Page Up
    • Page Down
    • Home
    • End
    • Enter

    What you can do is for example is make your element fill the whole space of your silverlight application by making it the exact size of your RootVisual and adjusting your margins to place it correctly in your application:

    XAML:

    <UserControl x:Class="SilverlightApplication1.MyRichTextBox"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button x:Name="FullScreen" Grid.Row="0" Content="FullScreen" Click="FullScreen_Click"  />
        <RichTextBox Grid.Row="1" />
    </Grid>
    

    Code-behind:

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    
    namespace SilverlightApplication1
    {
        public partial class MyRichTextBox : UserControl
        {
            private Thickness _oldMargin;
            private double _oldHeight = double.NaN;
            private double _oldWidth = double.NaN;
            private HorizontalAlignment _oldHorizontalAlignment;
            private VerticalAlignment _oldVerticalAlignment;
            private bool _fullScreen = false;
    
            public MyRichTextBox()
            {
                InitializeComponent();
            }
    
            private void FullScreen_Click(object sender, RoutedEventArgs e)
            {
                if (_fullScreen)
                {
                    _fullScreen = false;
                    Margin = _oldMargin;
                    Width = _oldWidth;
                    Height = _oldHeight;
                }
                else
                {
                    _fullScreen = true;
    
                    _oldMargin = Margin;
                    _oldWidth = Width;
                    _oldHeight = Height;
                    _oldHorizontalAlignment = HorizontalAlignment;
                    _oldVerticalAlignment = VerticalAlignment;
    
                    FrameworkElement rootVisual = Application.Current.RootVisual as FrameworkElement;
                    GeneralTransform generalTransform = TransformToVisual(rootVisual);
    
                    Point position = generalTransform.Transform(new Point(0, 0));
                    Width = rootVisual.ActualWidth;
                    Height =rootVisual.ActualHeight;
    
                    Margin = new Thickness(-position.X - 1, -position.Y - 1
                      , (ActualWidth + position.X) - rootVisual.ActualWidth - 1
                      , (ActualHeight + position.Y) - rootVisual.ActualHeight - 1);
                }
            }
        }
    }