Esempio n. 1
0
        public static void ApplyColumnInfo(DataGrid dataGrid, ColumnInfoObject colInfoList)
        {
            App _App = (App)Application.Current;

            // apply the column settings
            for (int i = 0; i < dataGrid.Columns.Count; i++)
            {
                ColumnInfo ci     = new ColumnInfo();
                var        lookup = (from a in colInfoList.ColumnInfoList
                                     where a.PropertyPath == ((Binding)((DataGridBoundColumn)dataGrid.Columns[i]).Binding).Path.Path
                                     //where a.Header == dataGrid.Columns[i].Header
                                     select a).FirstOrDefault();

                if (lookup == null)
                {
                    continue;
                }

                if (lookup.DisplayIndex == -1)
                {
                    continue;
                }

                // clear existing
                dataGrid.Columns[i].SortDirection = null;

                // set the sortdirection on the datagrid itself
                dataGrid.Columns[i].SortDirection = lookup.SortDirection;

                // width and display index
                dataGrid.Columns[i].DisplayIndex = lookup.DisplayIndex;
                dataGrid.Columns[i].Width        = new DataGridLength(lookup.WidthValue, lookup.WidthType);
            }

            // now apply the sort descriptions
            using (_App.GamesLibrary.LibraryView.DeferRefresh())
            {
                _App.GamesLibrary.LibraryView.SortDescriptions.Clear();
                for (int i = 0; i < colInfoList.SortDescriptionList.Count; i++)
                {
                    _App.GamesLibrary.LibraryView.SortDescriptions.Add(new SortDescription(colInfoList.SortDescriptionList[i].PropertyName, colInfoList.SortDescriptionList[i].Direction));
                }
            }
        }
Esempio n. 2
0
        //public ICollectionViewLiveShaping ShapingItems => LibraryView.View as ICollectionViewLiveShaping;

        public GamesLibraryViewModel()
        {
            // this.DataCollection = new ObservableCollectionEx<GamesLibraryModel>();
            this._DataCollection = new ObservableCollectionEx <GamesLibraryModel>();
            this.LibraryView     = new CollectionViewSource();

            DGStatesPath = AppDomain.CurrentDomain.BaseDirectory + @"Data\Settings\GamesLibraryColumnStates.json";
            LoadDataGridStatesFromDisk();
            if (DataGridStates == null)
            {
                // load defaults from disk
                DataGridStates = new List <ColumnInfoObject>();
                for (int i = 1; i < 26; i++)
                {
                    ColumnInfoObject coo = new ColumnInfoObject();
                    coo.FilterNumber        = i;
                    coo.ColumnInfoList      = new List <ColumnInfo>();
                    coo.SortDescriptionList = new Dictionary <int, SortDescription>();
                    DataGridStates.Add(coo);
                }
                LoadColumnDefaults();
            }



            IsDirty = true;
            Update();

            // bind the CollectionViewSource to our GamesLibraryModel DataCollection
            _LibraryView.Source = DataCollection;

            //ShapingItems.LiveSortingProperties.Add("Game");
            // ShapingItems.LiveSortingProperties.Add("System");
            // ShapingItems.IsLiveSorting = true;

            // multiplefilterhandlers
            MultipleFilter = new MultipleFilterHandler(LibraryView, MultipleFilterLogic.And);

            CurrentCountryFilter = GamesLibrary.CountryFilter.ALL;

            DataGridFocused = true;
        }
Esempio n. 3
0
        public static ColumnInfoObject GetColumnInfo(DataGrid dataGrid)
        {
            App _App             = (App)Application.Current;
            ColumnInfoObject coo = new ColumnInfoObject();

            List <ColumnInfo> list = new List <ColumnInfo>();

            foreach (DataGridColumn c in dataGrid.Columns)
            {
                ColumnInfo ci = new ColumnInfo(c);
                list.Add(ci);
            }

            coo.ColumnInfoList = list;

            // get sort descriptions from view
            coo.SortDescriptionList = new Dictionary <int, SortDescription>();
            for (int i = 0; i < _App.GamesLibrary.LibraryView.SortDescriptions.Count; i++)
            {
                coo.SortDescriptionList.Add(i, _App.GamesLibrary.LibraryView.SortDescriptions[i]);
            }

            return(coo);
        }