将DataGridColumn Save属性保存到Isolated Storage中

时间:2014-01-23 15:14:59

标签: wpf silverlight mvvm datagrid isolatedstorage

我有一个Datagrid,其属性必须在更改时自动保存。我正在使用ISOLATED STORAGE Settings来实现这一目标。截至目前,我正在存储DataGrid列的DISPLAY INDEX属性。

在我的代码背后,我试图将设置与DataGridName一起按如下方式推送

List<GridColumnSettings> settings = new List<GridColumnSettings>();
for (int index = 0; index < dcDataGrid.Columns.Count; index++)
            {
                DataGridColumn column = dcDataGrid.Columns[index];
                SettingsViewModel.GridColumnSettings setting = new GridColumnSettings(column.DisplayIndex, index);
                settings.Add(setting);
            }
**SendTemplatesSettingsViewModel.SaveSettings(settings, "dcBrowserDataGrid")**

SaveSettings方法看起来很喜欢这个

    public class SendTemplatesSettingsViewModel
        {

            public class GridColumnSettings
            {
                public int Index { get; set; } //Managing the column ordering of the DataGrid

                public int DisplayIndex { get; set; } //Store the Index/order of the column in the underlying datasource/ViewModel.

                public GridColumnSettings(int columnIndex, int displayIndex)
                {
                    this.DisplayIndex = columnIndex;
                    this.Index = displayIndex;
                }
            }
public void SaveSettings(List<SendTemplatesSettingsViewModel.GridColumnSettings> settings, string gridName)
        {
            mySettings.SetSetting<List<GridColumnSettings>>(gridName, settings);
        } 

SetSettings方法只是实例化ISOLATED存储并添加值。

我还想存储列的排序顺序,但我无法找到合适的属性来执行此操作。希望有人可以提供帮助提前谢谢。

1 个答案:

答案 0 :(得分:0)

我会使用集合视图源作为数据网格源,然后读/写SortDescriptions属性:http://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource(v=vs.110).aspx