1

我有一个带有richtextbox 的数据表单。用户可以键入一些文本并具有一些编辑功能,但我想为用户提供将编辑器扩展到全屏的选项,以获得更多的 Richtextbox 编辑选项。如何实现允许我全屏显示(或至少创建更大的窗口)richtexteditor 的功能,以便用户更好地了解文档和更多编辑选项?

这在 OOB 模式下是可能的。

4

1 回答 1

1

全屏无法工作,因为您在全屏时限制了键盘输入:

  • 向上箭头
  • 向下箭头
  • 左箭头
  • 右箭头
  • 空格键
  • 标签
  • 向上翻页
  • 向下翻页
  • 结尾
  • 进入

例如,您可以做的是让您的元素充满您的 Silverlight 应用程序的整个空间,方法是使其与您的 RootVisual 完全相同,并调整您的边距以将其正确放置在您的应用程序中:

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>

代码隐藏:

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);
            }
        }
    }
}
于 2010-09-02T17:18:20.103 回答