void AssociatedObject_LayoutUpdated(object sender, EventArgs e) { if (AssociatedObject == null || AssociatedObject.Items.Count == 0) { return; } GridViewHeaderRow headerRow = AssociatedObject.ChildrenOfType <GridViewHeaderRow>().FirstOrDefault(); if (headerRow == null) { return; } this.AssociatedObject.LayoutUpdated -= new EventHandler(AssociatedObject_LayoutUpdated); this.frozenRowsContainer = new RadGridView(); GenerateHeader(); SelectiveScrollingGrid grid = headerRow.ChildrenOfType <SelectiveScrollingGrid>().FirstOrDefault(); grid.RowDefinitions.Add(new RowDefinition()); grid.RowDefinitions.Add(new RowDefinition()); frozenRowsContainer.SetValue(Grid.RowProperty, 1); frozenRowsContainer.SetValue(Grid.ColumnSpanProperty, 4); frozenRowsContainer.SetValue(Grid.RowProperty, 1); frozenRowsContainer.ShowGroupPanel = false; frozenRowsContainer.ShowColumnHeaders = false; frozenRowsContainer.RowIndicatorVisibility = AssociatedObject.RowIndicatorVisibility; frozenRowsContainer.SetValue(SelectiveScrollingGrid.SelectiveScrollingOrientationProperty, SelectiveScrollingOrientation.Vertical); frozenRowsContainer.ItemsSource = this.PinnedItems; frozenRowsContainer.SetValue(ScrollViewer.HorizontalScrollBarVisibilityProperty, ScrollBarVisibility.Hidden); frozenRowsContainer.HorizontalAlignment = HorizontalAlignment.Left; grid.Children.Add(frozenRowsContainer); var scrollViewer = this.AssociatedObject.ChildrenOfType <GridViewScrollViewer>().FirstOrDefault(); scrollViewer.ScrollChanged += new ScrollChangedEventHandler(scrollViewer_ScrollChanged); this.frozenRowsContainer.SetBinding(FrameworkElement.WidthProperty, new Binding("ActualWidth") { Source = headerRow }); this.frozenRowsContainer.Margin = new Thickness(-1, 0, 0, 0); this.frozenRowsContainer.SetBinding(RadGridView.FrozenColumnCountProperty, new Binding("FrozenColumnCount") { Source = this.AssociatedObject, Mode = BindingMode.TwoWay }); this.PinItem(AssociatedObject.Items[0]); this.PinItem(AssociatedObject.Items[1]); this.PinItem(AssociatedObject.Items[2]); this.PinItem(AssociatedObject.Items[3]); SyncColumnWidths(); }
/// <summary> /// Method to catch click event to open context menu /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void RadContextMenu_Opened(object sender, RoutedEventArgs e) { if (sender == null || e == null) { return; } RadContextMenu menu = (RadContextMenu)sender; if (menu == null) { return; } GridViewRow row = menu.GetClickedElement <GridViewRow>(); GridViewGroupRow groupRow = menu.GetClickedElement <GridViewGroupRow>(); GridViewHeaderRow headerRow = menu.GetClickedElement <GridViewHeaderRow>(); if (row != null) { row.IsSelected = row.IsCurrent = true; (menu.Items[0] as RadMenuItem).IsEnabled = true; (menu.Items[1] as RadMenuItem).IsEnabled = true; (menu.Items[2] as RadMenuItem).IsEnabled = true; (menu.Items[3] as RadMenuItem).IsEnabled = true; return; } if (groupRow != null) { (menu.Items[0] as RadMenuItem).IsEnabled = true; (menu.Items[1] as RadMenuItem).IsEnabled = true; (menu.Items[2] as RadMenuItem).IsEnabled = true; (menu.Items[3] as RadMenuItem).IsEnabled = false; if (!(groupRow.Group.Key is string)) { return; } string groupName = groupRow.Group.Key as string; int itemCount = 0; foreach (MarketSnapshotPerformanceData item in this.radGridSnapshot.Items) { if (item.MarketSnapshotPreferenceInfo.GroupName == groupName && item.MarketSnapshotPreferenceInfo.EntityOrder == 1) { this.radGridSnapshot.SelectedItem = item; return; } itemCount++; } return; } if (headerRow != null) { (menu.Items[0] as RadMenuItem).IsEnabled = true; (menu.Items[1] as RadMenuItem).IsEnabled = false; (menu.Items[2] as RadMenuItem).IsEnabled = false; (menu.Items[3] as RadMenuItem).IsEnabled = false; return; } menu.IsOpen = false; }