views:

40

answers:

1

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. Thank you

+1  A: 

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);
            }
        }
    }
}
Peter Kiers
Thank you for your reply I have a couple of questions -Are you sure that the keyboard is limited - As I understand it Ashish Shetty explains in this Mix talk: http://live.visitmix.com/MIX10/Sessions/CL10 that in SL4 you have full keyboards support as opposed to limited in SL3.Also. Are you sure that the resizing of the richtextbox will work if it's in a dataform? Won't it just expand inside the dataform?
Jakob
An additioni to this problem is that -by design my app is not that large, so it would only be for users that actively chose a larger workspace for editing
Jakob
@Peter Kiers - I'll just add an at sign so you get the message, I'm not trying to spam with comments :D thanks for your attention
Jakob
The keyboard restriction is removed in Out-Of-Browser with elevated rights (http://msdn.microsoft.com/en-us/library/cc189023(VS.95).aspx). I just tested it with SL4 app, and still has restrictions other way.It will expand even in dataform (not tested though) cause I set the margin of the element to a negative value. You should be able to adjust the size yourself also if you only want half the screen or such.
Peter Kiers
thank you I'll have a go toorrow - I'm really tired now
Jakob
@Peter Kiers - I tried it, and it seems like it's able to bust out of the dataform borders, but ,y dataform is contained in a tabcontrol - do you have an idea of how to bust out of the tabcontrol aswell. It's ok if it's in a new windows as long as it goes in front of the rest of the application.
Jakob
But It would be neat if it could be larger than the actual application size which is 800 * 621
Jakob