using System;
using System.Windows;
using C1.Silverlight.DataGrid;

namespace C1DataGrid_Demo2010
{
    public partial class DemoGrid : System.Windows.Controls.UserControl
    {
        #region ** Object Model

        public DataGridHeadersVisibility HeadersVisibility
        {
            get
            {
                return grid.HeadersVisibility;
            }
            set
            {
                grid.HeadersVisibility = value;
            }
        }

        public DataGridGroupRowPosition GroupRowPosition
        {
            get
            {
                return grid.GroupRowPosition;
            }
            set
            {
                grid.GroupRowPosition = value;
            }
        }

        public bool ShowFluidMouseOver
        {
            get
            {
                return grid.ShowFluidMouseOver;
            }
            set
            {
                grid.ShowFluidMouseOver = value;
            }
        }

        public bool CanUserSort
        {
            get
            {
                return grid.CanUserSort;
            }
            set
            {
                grid.CanUserSort = value;
            }
        }

        public bool CanUserFilter
        {
            get
            {
                return grid.CanUserFilter;
            }
            set
            {
                grid.CanUserFilter = value;
            }
        }

        public bool CanUserGroup
        {
            get
            {
                return grid.CanUserGroup;
            }
            set
            {
                grid.CanUserGroup = value;
            }
        }

        public bool ShowGroupingPanel
        {
            get
            {
                return grid.ShowGroupingPanel;
            }
            set
            {
                grid.ShowGroupingPanel = value;
            }
        }

        public DataGridColumnFreezing CanUserFreezeColumns
        {
            get
            {
                return grid.CanUserFreezeColumns;
            }
            set
            {
                grid.CanUserFreezeColumns = value;
            }
        }

        public DataGridGridLinesVisibility GridLinesVisibility
        {
            get
            {
                return grid.GridLinesVisibility;
            }
            set
            {
                grid.GridLinesVisibility = value;
            }
        }

        public DataGridColumnFreezing ShowVerticalFreezingSeparator
        {
            get
            {
                return grid.ShowVerticalFreezingSeparator;
            }
            set
            {
                grid.ShowVerticalFreezingSeparator = value;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return grid.IsReadOnly;
            }
            set
            {
                grid.IsReadOnly = value;
            }
        }

        public bool IsLoading
        {
            get
            {
                return grid.IsLoading;
            }
            set
            {
                grid.IsLoading = value;
            }
        }

        public bool CanUserResizeColumns
        {
            get
            {
                return grid.CanUserResizeColumns;
            }
            set
            {
                grid.CanUserResizeColumns = value;
            }
        }

        public bool CanUserResizeRows
        {
            get
            {
                return grid.CanUserResizeRows;
            }
            set
            {
                grid.CanUserResizeRows = value;
            }
        }

        public bool CanUserAddRows
        {
            get
            {
                return grid.CanUserAddRows;
            }
            set
            {
                grid.CanUserAddRows = value;
            }
        }

        public bool CanUserRemoveRows
        {
            get
            {
                return grid.CanUserRemoveRows;
            }
            set
            {
                grid.CanUserRemoveRows = value;
            }
        }

        public bool CanUserEditRows
        {
            get
            {
                return grid.CanUserEditRows;
            }
            set
            {
                grid.CanUserEditRows = value;
            }
        }

        public int FrozenColumnCount
        {
            get
            {
                return grid.FrozenColumnCount;
            }
            set
            {
                grid.FrozenColumnCount = value;
            }
        }

        public DataGridSelectionMode SelectionMode
        {
            get
            {
                return grid.SelectionMode;
            }
            set
            {
                grid.SelectionMode = value;
            }
        }
        #endregion

        public DemoGrid()
        {
            InitializeComponent();

            DataContext = Data.GetProducts((product) => !string.IsNullOrEmpty(product.Element("ProductModelID").Value));
        }

        private void grid_AutoGeneratingColumn(object sender, C1.Silverlight.DataGrid.DataGridAutoGeneratingColumnEventArgs e)
        {
            Common.HandleColumnAutoGeneration(e);
            if (e.Property.Name == "Name" && e.Column is DataGridBoundColumn)
            {
                e.Column.Width = new DataGridLength(200);
                ((DataGridBoundColumn)e.Column).TextWrapping = TextWrapping.Wrap;
            }
        }

        private void grid_AutoGeneratedColumns(object sender, EventArgs e)
        {
            //grid.SortBy(grid.Columns["StandardCost"], DataGridSortDirection.Descending);
        }

        private void Refresh_Click(object sender, RoutedEventArgs e)
        {
            grid.Reload(true);
        }
    }
}
