#region Using
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Linq;
using System.Collections.Generic;
using Microsoft.Windows.Controls;
using Microsoft.Windows.Controls.Primitives;
#endregion

namespace MyProject.DataGridToolkit.Controls
{
///
/// DataGrid with integrated field chooser.
/// Took from :https://shemesh.wordpress.com/category/silverlight/
/// Right click on a column header to open the field chooser
/// and show/hide columns.
/// The VisibleColumns property is always up-to-date and can
/// be binded Two ways.
/// Im my case, I’m saving it to user prefereces fo consistency.
///
public class DataGridExtended : DataGrid
{

///
/// Gets or sets a value indicating the names of columns (as they appear in the column header)
/// to be visible, seperated by a semicolon.
/// columns that whose name is not here will be hidden.
///
public string VisibleColumns
{
get { return (string)GetValue(VisibleColumnsProperty); }
set { SetValue(VisibleColumnsProperty, value); }
}

#region ArrangeOverride
///
/// FrameworkElement.ArrangeOverride Method
/// =======================================
/// When overridden in a derived class,
/// positions child elements and determines a size for a FrameworkElement derived class.
///
/// The final area within the parent
/// that this element should use to arrange itself and its children
/// The actual size used
///
/// Notes to Inheritors:
/// Control authors who want to customize the arrange pass of layout processing
/// should override this method.
/// The implementation pattern should call Arrange on each visible child element,
/// and pass the final desired size for each child element as the finalRect parameter.
/// Parent elements should call Arrange on each child,
/// otherwise the child elements will not be rendered.
protected override Size ArrangeOverride(Size finalSize)
{