private void Page_Loaded(object sender, RoutedEventArgs e) { string xaml = Settings.Default.SearchColumns; if (!String.IsNullOrEmpty(xaml)) { //listView1.View = XamlReader.Parse(xaml) as GridView; var savedCols = XamlReader.Parse(xaml) as GridViewColumnCollection; GridViewColumnCollection cols = ((GridView)listView1.View).Columns; var theCols = new List <GridViewColumn>(); foreach (GridViewColumn col in savedCols) { theCols.Add(col); } cols.Clear(); savedCols.Clear(); foreach (GridViewColumn col in theCols) { col.HeaderTemplate = listView1.TryFindResource("HeaderTemplateSortNon") as DataTemplate; cols.Add(col); } } AddSortBinding(); }
public static void UpdateColumn(ListView listView, ColumnInfo[] colInfos) { GridViewColumnCollection columnCol = getColumnCols(listView); if (columnCol != null) { columnCol.Clear(); AddColumn(listView, columnCol, colInfos); } }
/// <summary> /// When the page is loaded, retrieve the persisted column layout /// This is a pretty grubby way of doing things but I couldn't think /// of anything better :/ /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Page_Loaded(object sender, RoutedEventArgs e) { //this event will fire not only when is first shown, but every time its shown // eg when switching between tabs. Not sure why if (_loaded) { return; } //fetch the layout from settings string xaml = Properties.Settings.Default.SearchColumns; if (!String.IsNullOrEmpty(xaml)) { GridViewColumnCollection savedCols = XamlReader.Parse(xaml) as GridViewColumnCollection; GridViewColumnCollection gridViewCols = ((GridView)listView1.View).Columns; //we can't share GridViewColumns between collections, nor can we //remove one during a foreach, so we have to copy them to a list, //then add them to the collection. List <GridViewColumn> tempCols = new List <GridViewColumn>(); foreach (GridViewColumn col in savedCols) { tempCols.Add(col); } gridViewCols.Clear(); savedCols.Clear(); //TODO: we should be using the existing converter resource rather than making a new one BooleanToVisibilityConverter boolToVisCon = new BooleanToVisibilityConverter(); foreach (GridViewColumn col in tempCols) { //add the templates, bindings, and set the visible states as these aren't persisted col.HeaderTemplate = listView1.TryFindResource("HeaderTemplateSortNon") as DataTemplate; GridViewColumnHeader gvch = col.Header as GridViewColumnHeader; MenuItem mnu = this.FindName("mnuCol" + gvch.Content.ToString()) as MenuItem; mnu.IsChecked = (gvch.Visibility == System.Windows.Visibility.Visible); Binding b = new Binding("IsChecked"); b.ElementName = "mnuCol" + gvch.Content.ToString(); b.Converter = boolToVisCon; gvch.SetBinding(UIElement.VisibilityProperty, b); gridViewCols.Add(col); } } _loaded = true; }
private void RefillColumns() { GridViewColumnCollection columns = (m_stackListView.View as GridView).Columns; columns.Clear(); if (m_showDecimalMenu.IsChecked) { GridViewColumn column = new GridViewColumn(); column.DisplayMemberBinding = new Binding("Value"); column.Header = "Decimal"; column.Width = Double.NaN; columns.Add(column); } if (m_showHexadecimalMenu.IsChecked) { GridViewColumn column = new GridViewColumn(); column.DisplayMemberBinding = new Binding("Hex"); column.Header = "Hexadecimal"; column.Width = Double.NaN; columns.Add(column); } if (m_showBinaryMenu.IsChecked) { GridViewColumn column = new GridViewColumn(); column.DisplayMemberBinding = new Binding("Binary"); column.Header = "Binary"; column.Width = Double.NaN; columns.Add(column); } if (m_showExpressionMenu.IsChecked) { GridViewColumn column = new GridViewColumn(); column.DisplayMemberBinding = new Binding("Expression"); column.Header = "Expression"; column.Width = 150; columns.Add(column); } }