Telerik Forums
UI for WPF Forum
3 answers
212 views

Kindly find the Below Code, this is the PrintExtensions Class that Prints an image of the Gridview data,
however on large amount of data, it takes maybe half an hour without doing anything and in the same time it consumes a lot of CPU memory.

but in small amount of data it works very fine. 
Any solution?

This is the Build of the rad controls I am using (RadControls for WPF, v.2012.2.1001.40)


Best Regards

public static class PrintExtensions
  
   {
  
       static FixedDocument ToFixedDocument(FrameworkElement element, PrintDialog dialog)
  
       {
  
  
  
           dialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
  
           PrintCapabilities capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket);
  
           Size pageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
  
           Size extentSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
  
           FixedDocument fixedDocument = new FixedDocument();
  
           element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  
           element.Arrange(new Rect(new Point(0, 0), element.DesiredSize));
  
           for (double y = 0; y < element.DesiredSize.Height; y += extentSize.Height)
  
           {
  
               for (double x = 0; x < element.DesiredSize.Width; x += extentSize.Width)
  
               {
  
                   VisualBrush brush = new VisualBrush(element);
  
                   brush.Stretch = Stretch.None;
  
                   brush.AlignmentX = AlignmentX.Left;
  
                   brush.AlignmentY = AlignmentY.Top;
  
                   brush.ViewboxUnits = BrushMappingMode.Absolute;
  
                   brush.TileMode = TileMode.None;
  
                   brush.Viewbox = new Rect(x, y, extentSize.Width, extentSize.Height);
  
                   PageContent pageContent = new PageContent();
  
                   FixedPage page = new FixedPage();
  
                   ((IAddChild)pageContent).AddChild(page);
  
                   fixedDocument.Pages.Add(pageContent);
  
                   page.Width = pageSize.Width;
  
                   page.Height = pageSize.Height;
  
                   Canvas canvas = new Canvas();
  
                   FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
  
                   FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);
  
                   canvas.Width = extentSize.Width;
  
                   canvas.Height = extentSize.Height;
  
                   canvas.Background = brush;
  
                   page.Children.Add(canvas);
  
  
  
               }
  
  
  
           }
  
           return fixedDocument;
 
  
  
       }
  
  
  
       static GridViewDataControl ToPrintFriendlyGrid(GridViewDataControl source)
  
       {
  
           var grid = new RadGridView()
  
           {
  
               ItemsSource = source.ItemsSource,
  
               RowIndicatorVisibility = Visibility.Collapsed,
  
               ShowGroupPanel = false,
  
               CanUserFreezeColumns = false,
  
               IsFilteringAllowed = false,
  
               EnableColumnVirtualization=false,
  
               AutoExpandGroups = true,
  
               AutoGenerateColumns = false,
  
               Margin=new Thickness(10,30,10,10),
  
               ShowColumnFooters=true,
  
               EnableRowVirtualization=true
  
                 
  
                 
  
           };
  
           double widthsum = 0;
  
           foreach (var column in source.Columns.OfType<GridViewDataColumn>())
  
           {
  
               widthsum += column.Width.DisplayValue;
  
           }
  
           foreach (var column in source.Columns.OfType<GridViewDataColumn>())
  
           {
  
                 
  
               GridViewDataColumn newColumn = new GridViewDataColumn();
  
               newColumn.Width = column.ActualWidth;
  
               newColumn.DisplayIndex = column.DisplayIndex;
  
               //newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
 
               newColumn.DataMemberBinding = column.DataMemberBinding; // Better to just copy the references to get all the custom formatting
 
               newColumn.DataFormatString = column.DataFormatString;
  
               newColumn.TextAlignment = column.TextAlignment;
  
               newColumn.Header = column.Header;
  
               newColumn.Footer = column.Footer;
  
               newColumn.Width = 1030/ widthsum * column.Width.DisplayValue;
  
                 
  
               if (column.DataType.Name == "Decimal")
  
               {
  
                   //newColumn.TextAlignment = TextAlignment.Right;
  
                   SumFunction sum = new SumFunction { ResultFormatString = "Total : {0}", Caption = "" };
  
                   sum.ResultFormatString = "{0:n}";
  
                   newColumn.AggregateFunctions.Add(sum);
  
                   newColumn.FooterTextAlignment = TextAlignment.Right;
  
               }
  
               else
  
               {
  
                   newColumn.TextWrapping = TextWrapping.Wrap;
  
                     
  
               }
  
  
  
  
  
  
  
               grid.Columns.Add(newColumn);
  
           }
  
  
  
  
  
            
  
           StyleManager.SetTheme(grid, StyleManager.GetTheme(grid));
  
  
  
           grid.SortDescriptors.AddRange(source.SortDescriptors);
  
           grid.GroupDescriptors.AddRange(source.GroupDescriptors);
  
           grid.FilterDescriptors.AddRange(source.FilterDescriptors);
  
              
  
           return grid;
  
       }
  
  
  
       public enum ZoomType
  
       {
  
           Full,
  
           Width,
  
           Height,
  
           TwoWide
  
  
  
  
  
  
  
       };
  
  
  
  
  
       private static double constrain(double val, double val_min, double val_max)
  
       {
  
           if (val < val_min) return val_min;
  
           else if (val > val_max) return val_max;
  
           else return val;
  
       }
 
  
  
  
  
       public static void PrintPreview(this GridViewDataControl source,string title)
  
       {
  
  
  
           Window window = new Window();
  
           window.Title = "Print Preview";
  
           if (!string.IsNullOrWhiteSpace(source.ToolTip as string)) window.Title += " of " + source.ToolTip;
  
           window.Width = SystemParameters.PrimaryScreenWidth * 0.92;
  
           window.Height = SystemParameters.WorkArea.Height;
  
           window.Left = constrain(SystemParameters.VirtualScreenWidth - SystemParameters.PrimaryScreenWidth, 0, SystemParameters.VirtualScreenWidth - 11);
  
           window.Top = constrain(0, 0, SystemParameters.VirtualScreenHeight - 25);
  
           DocumentViewer viewer = new DocumentViewer();
  
           viewer.Document = ToFixedDocument(ToPrintFriendlyGrid(source), new PrintDialog());
  
           Zoom(viewer, ZoomType.Full);
  
           window.Content = viewer;
  
           window.Show();
  
  
  
       }
  
  
  
       public static void Zoom(DocumentViewer viewer, ZoomType zoom)
  
       {
  
           switch (zoom)
  
           {
  
               case ZoomType.Height: viewer.FitToHeight(); break;
  
               case ZoomType.Width: viewer.FitToWidth(); break;
  
               case ZoomType.TwoWide: viewer.FitToMaxPagesAcross(2); break;
  
               case ZoomType.Full: break;
  
           }
  
  
  
  
  
  
  
       }
 
  
  
       public static void Print(this GridViewDataControl source, bool showDialog, string title)
  
       {
  
           var dialog = new PrintDialog();
  
           var dialogResult = showDialog ? dialog.ShowDialog() : true;
  
  
  
           if (dialogResult == true)
  
           {
  
               var viewer = new DocumentViewer();
  
               Grid maingrid = new Grid();
  
               ColumnDefinition gridCol1 = new ColumnDefinition();
  
               maingrid.ColumnDefinitions.Add(gridCol1);
  
               RowDefinition gridRow1 = new RowDefinition();
  
               RowDefinition gridRow2 = new RowDefinition();
  
               maingrid.RowDefinitions.Add(gridRow1);
  
               maingrid.RowDefinitions.Add(gridRow2);
  
  
  
               TextBlock txtBlock1 = new TextBlock();
  
               txtBlock1.Text = title;
  
               txtBlock1.Margin = new Thickness(2, 2, 2, 2);
  
               txtBlock1.TextAlignment = TextAlignment.Center;
  
  
  
  
  
               Grid.SetRow(txtBlock1, 0);
  
               Grid.SetRow(ToPrintFriendlyGrid(source), 1);
  
               maingrid.Children.Add(txtBlock1);
  
               maingrid.Children.Add(ToPrintFriendlyGrid(source));
  
  
  
               viewer.Document = ToFixedDocument(maingrid, dialog);
  
               dialog.PrintDocument(viewer.Document.DocumentPaginator, "");
  
           }
  
       }
  
   }



Dimitrina
Telerik team
 answered on 12 Nov 2013
1 answer
118 views
Hi,

Is it possible to hide or show a field (table, span etc) based on a mergefield value.

Similar to the feature available in Microsoft Word.

I.e. (setting an expression)

If mergefield.invoiced == true then fieldname.show else fieldname.hide

Thanks, 

Rob
Boby
Telerik team
 answered on 12 Nov 2013
5 answers
537 views
Hi Telerick,

I am testing telerik for PRISM + Unity. 
All of control is beyond my expectation and working great.

However, I experienced one major issue when using RegionManager.RequestNavigate after closing RadPane.
When caller navigates with bookId, there is no issue when the book id is new. The new view is created and activated well.
But I met two issue when the book id exits on list of view.
First, The existing view is not activated after RegionManager.RequestNavigate 
Second, I closed the one book view and called RegionManager.RequestNavigate  with the book id. In this time, Not thing happens.
The old view looks like alive in the view list....

I am using RadPaneGroupRegionAdapter which comes from your blog
And I tried to DockingExtension on forum but showing same issues.
I spend almost two weeks in order solve this issue but I can't get any clue... 

1. ------------- caller ---------------
query.Add("BookId", book.Id.ToString());

RegionManager.RequestNavigate( RegionName.MainContent, new Uri("BookView" + query.ToString(), UriKind.Relative), NavigationComplted);

2. -------    BookViewModel
public bool IsNavigationTarget(NavigationContext navigationContext)
{
UriQuery query = navigationContext.Parameters;
int bookId = Convert.ToInt32(query["BookId"]);

if (this.BookId == bookId)
return true;

return false;
}


3. --- RegionAdapter comes from your blog

public class RadPaneGroupRegionAdapter : RegionAdapterBase<RadPaneGroup>
    {
        public RadPaneGroupRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory)
            : base(regionBehaviorFactory)
        {
 
        }
 
        protected override void AttachBehaviors(IRegion region, RadPaneGroup regionTarget)
        {
            base.AttachBehaviors(region, regionTarget);
        }
 
        
 
        protected override void Adapt(IRegion region, RadPaneGroup regionTarget)
        {
            
            region.Views.CollectionChanged += (s, e) =>
            {
                switch (e.Action)
                {
                    case NotifyCollectionChangedAction.Add:
                        foreach (var item in e.NewItems.OfType<RadPane>())
                        {
                            regionTarget.Items.Add(item);
                        }
                        break;
                    case NotifyCollectionChangedAction.Remove:
                        foreach (var item in e.OldItems.OfType<RadPane>())
                        {
                            //regionTarget.Items.Remove(item);
                            item.RemoveFromParent();
                        }
                        break;
                    case NotifyCollectionChangedAction.Replace:
                        var oldItems = e.OldItems.OfType<RadPane>();
                        var newItems = e.NewItems.OfType<RadPane>();
                        var newItemsEnumerator = newItems.GetEnumerator();
                        foreach (var oldItem in oldItems)
                        {
                            var parent = oldItem.Parent as ItemsControl;
                            if (parent != null && parent.Items.Contains(oldItem))
                            {
                                parent.Items[parent.Items.IndexOf(oldItem)] = newItemsEnumerator.Current;
                                if (!newItemsEnumerator.MoveNext())
                                {
                                    break;
                                }
                            }
                            else
                            {
                                oldItem.RemoveFromParent();
                                regionTarget.Items.Add(newItemsEnumerator.Current);
                            }
                        }
                        break;
                    case NotifyCollectionChangedAction.Reset:
                        regionTarget
                            .EnumeratePanes()
                            .ToList()
                            .ForEach(p => p.RemoveFromParent());
 
                        foreach (var view in region.Views)
                        {
                            regionTarget.Items.Add(view);
                        }
 
                        break;
                    default:
                        break;
                }
            };
 
            foreach (var view in region.Views.OfType<RadPane>())
            {
                regionTarget.Items.Add(view);
            }
        }
 
        protected override IRegion CreateRegion()
        {
            return new AllActiveRegion();
        }
    }


4. -- Docking Extension

   public class DockingExtensions
    {
        public static bool GetRemovePanesWhenClosed(DependencyObject obj)
        {
            return (bool)obj.GetValue(RemovePanesWhenClosedProperty);
        }
 
        public static void SetRemovePanesWhenClosed(DependencyObject obj, bool value)
        {
            obj.SetValue(RemovePanesWhenClosedProperty, value);
        }
 
        public static readonly DependencyProperty RemovePanesWhenClosedProperty =
            DependencyProperty.RegisterAttached("RemovePanesWhenClosed"typeof(bool), typeof(DockingExtensions), new PropertyMetadata(false, OnRemovePanesWhenClosedPropertyChanged));
 
        private static void OnRemovePanesWhenClosedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var newValue = (bool)e.NewValue;
            var dock = d as RadDocking;
 
            if (dock != null)
            {
                if (newValue)
                {
                    dock.PreviewClose += dock_PreviewClose;
                }
                else
                {
                    dock.PreviewClose -= dock_PreviewClose;
                }
            }
        }
 
        private static void dock_PreviewClose(object sender, Telerik.Windows.Controls.Docking.StateChangeEventArgs e)
        {
            foreach (var pane in e.Panes)
            {
                DependencyObject o = pane.Parent;
 
 
                pane.RemoveFromParent();
                pane.Content = null;
                pane.Header = null;
                pane.DataContext = null;
            }
            e.Handled = true;
        }
    }
George
Telerik team
 answered on 11 Nov 2013
1 answer
132 views
Hi Telerik Support,

I want to dynamically change the Foreground Color of the tabheader. (i.e)When I drag and drop a new tab in the Main Window, The tabHeader Foreground Color have to change. How to achieve this? I am using Q2 version in my Application.

Thanks,
Vinnarasi
Kalin
Telerik team
 answered on 11 Nov 2013
3 answers
144 views
Hello,
I'm defining custom filters that inherits from existing filters. In Silverlight, I have no problem with this, but in WPF, the custom filters doesn't show all the options the first time it is displayed.

For example, if I define my custom filter as:
Namespace OrdinaSoft.Windows.Controls;
 
Interface
 
  Uses
    System.Windows,
 
    Telerik.Windows.Controls,
    Telerik.Windows.Controls.GridView,
    Telerik.Windows.Data;
 
  Type
    FilteringControl Nested In osRadGridViewTextColumn = Private Sealed Class (
      Telerik.Windows.Controls.GridView.FilteringControl
    )
 
    Public
 
      Constructor;
 
      Method Prepare (Column : GridViewColumn); Override;
 
    End;
 
Implementation
 
  Constructor osRadGridViewTextColumn.FilteringControl;
  Begin
    Style := System.Windows.Style (Application.Current.Resources ['FilteringControlStyle'])
  End;
 
  Method osRadGridViewTextColumn.FilteringControl.Prepare (
    Column : GridViewColumn
  );
  Begin
    Inherited Prepare (Column);
  End;
 
 
End.

Actually, this filter does nothing, it just inherits from the Telerik one.
Now, when I click on the funnel, the first time, the filter only displays the combo boxes, as you can see in the enclosed screen shot.
The second time the filter is displayed, it contains all the items.

Patrick
Yoan
Telerik team
 answered on 11 Nov 2013
13 answers
840 views
Hello everybody,

After migration to new Telerik Controls 2013 Q2 I've faced with some issues in grid view validating.

All items which bound to RadGridView have two validation attributes: Require from System.ComponentModel and my own attribute which inherited from ValidationAttribute.
WIth new Telerik assemblies it is incorrect row highlighting after validation was finished. Row is valid actually, but it has error message and error background (in attached screenshot). If you scroll grid up and down, than background will become normal and error message will disappear.
In debugger when code in RowValidated handle row has IsValid=true, but row Errors collection have 1 error description.

I've attached sample project where this issue is reproduced.

Do you know any ways to workaround this issue?
Thanks!
Vera
Telerik team
 answered on 11 Nov 2013
5 answers
219 views
Hi,

We are using the RadGridView in our project and we have also made use of the lightweight templates to try and improve the slow load times of the grid. However, after implementing the lightweight templates we appear to have lost the gridlines. Is there anyway to get the gridlines back when using the templates?

Thanks
Vanya Pavlova
Telerik team
 answered on 11 Nov 2013
1 answer
133 views
I have attached two pictures to demonstrate the issue.

The grid lines represent 1 minute intervals.

The first image shows the appointment being sized or dragged and it displays the start time and end time (2 to 3 minutes)

The second image shows the result when the appointment appears on the timeline.
Notice it is not aligned with the grid lines (should be between tick marks 2 and 3), I am not sure how to solve this offset problem..

Any help would be appreciated.
Rosi
Telerik team
 answered on 11 Nov 2013
5 answers
143 views
Hello,

I have a RadComboBox (from the Q3/2013 release) with say 10 items and I am using the Windows8TouchTheme. On my win8.1 tablet the scrolling of the dropdown list is very (very, very) slow, when I swipe over the items. First nothing happens, then it scrolls a few items down or up. When I swipe over the scrollbar the performance is normal as expected.

Any ideas?

Erik
Alek
Telerik team
 answered on 11 Nov 2013
4 answers
184 views
I need to position all child of  RadTileList to the center, I already try with HorizontalContentAlignment and set it to Center the content (i mean the child) still positioned on the left, why is that happen
Vanya Pavlova
Telerik team
 answered on 11 Nov 2013
Narrow your results
Selected tags
Tags
GridView
General Discussions
Chart
RichTextBox
Docking
ScheduleView
ChartView
TreeView
Diagram
Map
ComboBox
TreeListView
Window
RibbonView and RibbonWindow
PropertyGrid
DragAndDrop
TabControl
TileView
Carousel
DataForm
PDFViewer
MaskedInput (Numeric, DateTime, Text, Currency)
AutoCompleteBox
DatePicker
Buttons
ListBox
GanttView
PivotGrid
Spreadsheet
Gauges
NumericUpDown
PanelBar
DateTimePicker
DataFilter
Menu
ContextMenu
TimeLine
Calendar
Installer and Visual Studio Extensions
ImageEditor
BusyIndicator
Expander
Slider
TileList
PersistenceFramework
DataPager
Styling
TimeBar
OutlookBar
TransitionControl
Book
FileDialogs
ToolBar
ColorPicker
TimePicker
SyntaxEditor
MultiColumnComboBox
VirtualGrid
Wizard
ExpressionEditor
NavigationView (Hamburger Menu)
DesktopAlert
WatermarkTextBox
BarCode
SpellChecker
DataServiceDataSource
EntityFrameworkDataSource
RadialMenu
ChartView3D
Data Virtualization
BreadCrumb
ProgressBar
Sparkline
LayoutControl
TabbedWindow
ToolTip
CloudUpload
ColorEditor
TreeMap and PivotMap
EntityFrameworkCoreDataSource (.Net Core)
HeatMap
Chat (Conversational UI)
VirtualizingWrapPanel
Calculator
NotifyIcon
TaskBoard
TimeSpanPicker
BulletGraph
Licensing
WebCam
CardView
DataBar
FilePathPicker
PasswordBox
Rating
SplashScreen
Accessibility
Callout
CollectionNavigator
Localization
AutoSuggestBox
VirtualKeyboard
HighlightTextBlock
Security
TouchManager
StepProgressBar
Badge
OfficeNavigationBar
ExpressionParser
CircularProgressBar
SvgImage
PipsPager
SlideView
AI Coding Assistant
+? more
Top users last month
Ambisoft
Top achievements
Rank 2
Iron
Pascal
Top achievements
Rank 2
Iron
Matthew
Top achievements
Rank 1
Sergii
Top achievements
Rank 1
Iron
Iron
Andrey
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Ambisoft
Top achievements
Rank 2
Iron
Pascal
Top achievements
Rank 2
Iron
Matthew
Top achievements
Rank 1
Sergii
Top achievements
Rank 1
Iron
Iron
Andrey
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?