Пример #1
0
        private static RadWindow CreatePreviewWindow(RadRichTextBox rtb)
        {
            var printButton = new RadButton
                {
                    Content = "Print",
                    Margin = new Thickness(10, 0, 10, 0),
                    FontWeight = FontWeights.Bold,
                    Width = 80
                };

            printButton.Click += (s, e) => rtb.Print("MyDocument", Telerik.Windows.Documents.UI.PrintMode.Native);

            var sp = new StackPanel { Height = 26, Orientation = Orientation.Horizontal, Margin = new Thickness(10) };
            sp.Children.Add(new RadRichTextBoxStatusBar { AssociatedRichTextBox = rtb, Margin = new Thickness(20, 0, 10, 0) });

            sp.Children.Add(new TextBlock
                {
                    Text = "Orientation:",
                    Margin = new Thickness(10, 0, 3, 0),
                    VerticalAlignment = VerticalAlignment.Center
                });

            var radComboBoxPageOrientation = new RadComboBox
                {
                    ItemsSource = new[] { "Portrait", "Landscape" },
                    SelectedIndex = 0
                };
            sp.Children.Add(radComboBoxPageOrientation);

            radComboBoxPageOrientation.SelectionChanged +=
                (s, e) => rtb.ChangeSectionPageOrientation((PageOrientation)Enum.Parse(typeof(PageOrientation),
                                                                                        radComboBoxPageOrientation.Items
                                                                                            [
                                                                                                radComboBoxPageOrientation
                                                                                                    .SelectedIndex]
                                                                                            .ToString(), true));

            sp.Children.Add(new TextBlock
                {
                    Text = "Size:",
                    Margin = new Thickness(10, 0, 3, 0),
                    VerticalAlignment = VerticalAlignment.Center
                });

            var radComboBoxPageSize = new RadComboBox
                {
                    ItemsSource = new[] { "A0", "A1", "A2", "A3", "A4", "A5", "Letter" },
                    Height = 25,
                    SelectedIndex = 4,
                };
            sp.Children.Add(radComboBoxPageSize);

            radComboBoxPageSize.SelectionChanged += (s, e) =>
                rtb.ChangeSectionPageSize(PaperTypeConverter.ToSize((PaperTypes)Enum.Parse(typeof(PaperTypes),
                                                                                            radComboBoxPageSize.Items[
                                                                                                radComboBoxPageSize
                                                                                                    .SelectedIndex]
                                                                                                .ToString(), true)));

            sp.Children.Add(printButton);

            var g = new Grid();
            g.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
            g.RowDefinitions.Add(new RowDefinition());
            g.Children.Add(sp);
            g.Children.Add(rtb);

            Grid.SetRow(rtb, 1);

            return new RadWindow
                {
                    Content = g,
                    Width = 900,
                    Height = 600,
                    Header = "Print Preview",
                    WindowStartupLocation = Telerik.Windows.Controls.WindowStartupLocation.CenterScreen
                };
        }
        private static RadWindow CreatePreviewWindow(RadRichTextBox rtb)
        {
            var printButton = new RadButton()
            {
                Content    = "Print",
                Margin     = new Thickness(10, 0, 10, 0),
                FontWeight = FontWeights.Bold,
                Width      = 80
            };

            printButton.Click += (s, e) =>
            {
                rtb.Print("MyDocument", Telerik.Windows.Documents.UI.PrintMode.Native);
            };

            var sp = new StackPanel()
            {
                Height = 26, Orientation = Orientation.Horizontal, Margin = new Thickness(10)
            };

            sp.Children.Add(new RadRichTextBoxStatusBar()
            {
                AssociatedRichTextBox = rtb, Margin = new Thickness(20, 0, 10, 0)
            });

            sp.Children.Add(new TextBlock()
            {
                Text = "Orientation:", Margin = new Thickness(10, 0, 3, 0), VerticalAlignment = VerticalAlignment.Center
            });

            var radComboBoxPageOrientation = new RadComboBox()
            {
                ItemsSource   = new string[] { "Portrait", "Landscape" },
                SelectedIndex = 0
            };

            sp.Children.Add(radComboBoxPageOrientation);

            radComboBoxPageOrientation.SelectionChanged += (s, e) =>
            {
                rtb.ChangeSectionPageOrientation((PageOrientation)Enum.Parse(typeof(PageOrientation),
                                                                             radComboBoxPageOrientation.Items[radComboBoxPageOrientation.SelectedIndex].ToString(), true));
            };

            sp.Children.Add(new TextBlock()
            {
                Text = "Size:", Margin = new Thickness(10, 0, 3, 0), VerticalAlignment = VerticalAlignment.Center
            });

            var radComboBoxPageSize = new RadComboBox()
            {
                ItemsSource   = new string[] { "A0", "A1", "A2", "A3", "A4", "A5", "Letter" },
                Height        = 25,
                SelectedIndex = 4,
            };

            sp.Children.Add(radComboBoxPageSize);

            radComboBoxPageSize.SelectionChanged += (s, e) =>
            {
                rtb.ChangeSectionPageSize(PaperTypeConverter.ToSize((PaperTypes)Enum.Parse(typeof(PaperTypes),
                                                                                           radComboBoxPageSize.Items[radComboBoxPageSize.SelectedIndex].ToString(), true)));
            };

            sp.Children.Add(printButton);

            var g = new Grid();

            g.RowDefinitions.Add(new RowDefinition()
            {
                Height = GridLength.Auto
            });
            g.RowDefinitions.Add(new RowDefinition());
            g.Children.Add(sp);
            g.Children.Add(rtb);

            Grid.SetRow(rtb, 1);

            return(new RadWindow()
            {
                Content = g,
                Width = 900,
                Height = 600,
                Header = "Print Preview",
                WindowStartupLocation = WindowStartupLocation.CenterOwner,
                Owner = WpfHelper.GetActiveWindow()
            });
        }