public PropertyItemsControl() { #if !NET40 VirtualizingPanel.SetIsVirtualizingWhenGrouping(this, true); VirtualizingPanel.SetScrollUnit(this, ScrollUnit.Pixel); #endif }
public ScrollPanel() { VerticalScrollBarVisibility = ScrollBarVisibility.Auto; HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; Effect = new DropShadowEffect() { BlurRadius = 10, Direction = 270, RenderingBias = RenderingBias.Performance, ShadowDepth = 0 }; Panel = new StackPanel() { HorizontalAlignment = HorizontalAlignment.Center }; VirtualizingPanel.SetIsVirtualizing(Panel, true); VirtualizingPanel.SetVirtualizationMode(Panel, VirtualizationMode.Recycling); Content = Panel; ZoomMode = PdfViewerZoomMode.FitHeight; Rotate = PdfRotation.Rotate0; Flags = PdfRenderFlags.None; PagesDisplayMode = PdfViewerPagesDisplayMode.SinglePageMode; MouseWheelMode = MouseWheelMode.PanAndZoom; Dpi = 96; ScrollWidth = 50; Zoom = 1; ZoomMin = DefaultZoomMin; ZoomMax = DefaultZoomMax; ZoomFactor = DefaultZoomFactor; FrameSpace = new Thickness(5); }
private void CustomListView_Loaded(object sender, RoutedEventArgs e) { _scrollViewer = VisualSearchHelper.GetChildObject <ScrollViewer>(this, string.Empty); ScrollViewer.SetHorizontalScrollBarVisibility(this, ScrollBarVisibility.Disabled); ScrollViewer.SetCanContentScroll(this, true); VirtualizingPanel.SetIsVirtualizing(this, true); //设置ScrollUnit ScrollUnit scrollUnit; switch (CustomSlidingMode) { case SlidingModeType.Pixel: scrollUnit = ScrollUnit.Pixel; break; case SlidingModeType.Row: scrollUnit = ScrollUnit.Item; break; default: scrollUnit = ScrollUnit.Pixel; break; } VirtualizingPanel.SetScrollUnit(this, scrollUnit); }
private void OnLoaded(object sender, RoutedEventArgs e) { _scrollContainer = this.FindVisualChild <ScrollViewer>(); _itemsPanel = _scrollContainer.FindVisualChild <VirtualizingPanel>(); _itemsPanel.SizeChanged += OnItemsPanelSizeChanged; }
protected override void OnSelectionChanged(SelectionChangedEventArgs e) { base.OnSelectionChanged(e); bool isVirtualizing = VirtualizingPanel.GetIsVirtualizing(this); bool isMultiSelect = this.SelectionMode != SelectionMode.Single; if (isVirtualizing && isMultiSelect) { var newSelectedItems = this.SelectedItems.Cast <IListItemViewModel>().ToList(); foreach (var deselectedItem in this.selectedItems.Except(newSelectedItems)) { deselectedItem.IsSelected = false; } this.selectedItems.Clear(); this.selectedItems.AddRange(newSelectedItems); foreach (var newlySelectedItem in this.selectedItems) { newlySelectedItem.IsSelected = true; } } }
// Token: 0x06005CFE RID: 23806 RVA: 0x001A2A4B File Offset: 0x001A0C4B private void InvalidateDataGridCellsPanelMeasureAndArrange(bool withColumnVirtualization) { if (withColumnVirtualization == VirtualizingPanel.GetIsVirtualizing(this)) { this.InvalidateDataGridCellsPanelMeasureAndArrange(); } }
public VirtualizingItemsControl() { ItemsPanel = new ItemsPanelTemplate(new FrameworkElementFactory(typeof(VirtualizingStackPanel))); string template = @" <ControlTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'> <Border BorderThickness='{TemplateBinding Border.BorderThickness}' Padding='{TemplateBinding Control.Padding}' BorderBrush='{TemplateBinding Border.BorderBrush}' Background='{TemplateBinding Panel.Background}' SnapsToDevicePixels='True'> <ScrollViewer Padding='{TemplateBinding Control.Padding}' Focusable='False'> <ItemsPresenter SnapsToDevicePixels='{TemplateBinding UIElement.SnapsToDevicePixels}'/> </ScrollViewer> </Border> </ControlTemplate>"; Template = (ControlTemplate)XamlReader.Parse(template); ScrollViewer.SetCanContentScroll(this, true); ScrollViewer.SetVerticalScrollBarVisibility(this, ScrollBarVisibility.Auto); ScrollViewer.SetHorizontalScrollBarVisibility(this, ScrollBarVisibility.Auto); VirtualizingPanel.SetCacheLengthUnit(this, VirtualizationCacheLengthUnit.Page); VirtualizingPanel.SetCacheLength(this, new VirtualizationCacheLength(1)); VirtualizingPanel.SetIsVirtualizingWhenGrouping(this, true); }
/// <summary> /// Manually select the items... /// </summary> /// <param name="e">SelectionChangedEventArgs</param> protected override void OnSelectionChanged(SelectionChangedEventArgs e) { base.OnSelectionChanged(e); bool isVirtualizing = VirtualizingPanel.GetIsVirtualizing(this); bool isMultiSelect = (SelectionMode != SelectionMode.Single); if (isVirtualizing && isMultiSelect) { var newSelectedItems = SelectedItems.Cast <IScrobbableObjectViewModel>(); foreach (var deselectedItem in selectedItems.Except(newSelectedItems)) { deselectedItem.UpdateIsSelectedSilent(false); } selectedItems.Clear(); selectedItems.AddRange(newSelectedItems); foreach (var newlySelectedItem in selectedItems) { newlySelectedItem.UpdateIsSelectedSilent(true); } // todo: kinda hacky way to update the view... var lastItem = selectedItems.LastOrDefault(); if (lastItem != null) { lastItem.IsSelected = true; } } }
/// <summary> /// Obtain the IRawElementProviderSimple at an absolute position /// </summary> IRawElementProviderSimple IGridProvider.GetItem(int row, int column) { if (row < 0 || row >= ((IGridProvider)this).RowCount) { throw new ArgumentOutOfRangeException("row"); } if (column < 0 || column >= ((IGridProvider)this).ColumnCount) { throw new ArgumentOutOfRangeException("column"); } ListViewItem lvi = _listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem; //If item is virtualized, try to de-virtualize it if (lvi == null) { VirtualizingPanel itemsHost = _listview.ItemsHost as VirtualizingPanel; if (itemsHost != null) { itemsHost.BringIndexIntoView(row); } lvi = _listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem; if (lvi != null) { //Must call Invoke here to force run the render process _listview.Dispatcher.Invoke( System.Windows.Threading.DispatcherPriority.Loaded, (System.Windows.Threading.DispatcherOperationCallback) delegate(object arg) { return(null); }, null); } } //lvi is null, it is virtualized, so we can't return its cell if (lvi != null) { AutomationPeer lvpeer = UIElementAutomationPeer.FromElement(_listview); if (lvpeer != null) { List <AutomationPeer> rows = lvpeer.GetChildren(); //Headers is the first child of GridView, so we need to skip it here if (rows.Count - 1 > row) { AutomationPeer peer = rows[row + 1]; List <AutomationPeer> columns = peer.GetChildren(); if (columns.Count > column) { return(ElementProxy.StaticWrap(columns[column], lvpeer)); } } } } return(null); }
public static void SetStyles() { Eto.Style.Add <Eto.Forms.Button>("main", button => { var wpfbutton = (Button)button.ControlObject; wpfbutton.BorderThickness = new Thickness(0.0); var img = (Image)((Grid)wpfbutton.Content).Children[0]; img.Margin = new Thickness(5.0d); var label = (Label)((Grid)wpfbutton.Content).Children[1]; label.HorizontalAlignment = HorizontalAlignment.Left; TextOptions.SetTextRenderingMode(label, TextRenderingMode.Auto); }); Eto.Style.Add <Eto.Forms.Button>("donate", button => { var wpfbutton = (Button)button.ControlObject; wpfbutton.BorderThickness = new Thickness(0.0); var img = (Image)((Grid)wpfbutton.Content).Children[0]; img.Margin = new Thickness(5.0d); var label = (Label)((Grid)wpfbutton.Content).Children[1]; label.HorizontalAlignment = HorizontalAlignment.Left; TextOptions.SetTextRenderingMode(label, TextRenderingMode.Auto); }); Eto.Style.Add <Eto.Forms.Panel>("transparent-form", control => { var wpfwnd = (System.Windows.Window)control.ControlObject; TextOptions.SetTextRenderingMode(wpfwnd, TextRenderingMode.Auto); wpfwnd.AllowsTransparency = true; wpfwnd.Background = Brushes.Transparent; }); Eto.Style.Add <Eto.Forms.TextBox>("textbox-rightalign", control => { var tbox = (System.Windows.Controls.TextBox)control.ControlObject; tbox.TextAlignment = TextAlignment.Right; }); Eto.Style.Add <Eto.Forms.GridView>("spreadsheet", control => { var wpfgrid = (Eto.Wpf.Forms.Controls.EtoDataGrid)control.ControlObject; wpfgrid.SelectionUnit = DataGridSelectionUnit.Cell; var style = new Style(typeof(DataGridColumnHeader)); style.Setters.Add(new Setter(DataGrid.HorizontalContentAlignmentProperty, HorizontalAlignment.Center)); wpfgrid.ColumnHeaderStyle = style; wpfgrid.ColumnWidth = new DataGridLength(100, DataGridLengthUnitType.Pixel); wpfgrid.HeadersVisibility = DataGridHeadersVisibility.All; wpfgrid.RowHeaderWidth = 50; wpfgrid.EnableColumnVirtualization = true; wpfgrid.EnableRowVirtualization = true; VirtualizingPanel.SetVirtualizationMode(wpfgrid, VirtualizationMode.Recycling); VirtualizingStackPanel.SetIsVirtualizing(wpfgrid, true); wpfgrid.LoadingRow += (sender, e) => { e.Row.Header = (e.Row.GetIndex() + 1).ToString(); }; wpfgrid.UpdateLayout(); }); }
public SearchAndResultsControl() { InitializeComponent(); typingConcurrentOperation.DisplayResults += (r, moreAvailable) => DisplaySearchResults(r, moreAvailable); typingConcurrentOperation.SearchComplete += TypingConcurrentOperation_SearchComplete; VirtualizingPanel.SetIsVirtualizing(resultsList, SettingsService.EnableTreeViewVirtualization); }
/// <summary> /// Initializes a new instance of the <see cref="ItemVirtualizer"/> class. /// </summary> /// <param name="owner"></param> public ItemVirtualizer(ItemsPresenter owner) { Owner = owner; _scrollViewer = VirtualizingPanel.FindAncestorOfType <ScrollViewer>(); if ((owner.TemplatedParent is ItemsControl ic) && !(owner.TemplatedParent is GroupItem)) { GroupControl = new GroupController(ic, Vertical); }
public ListControl() { BorderThickness = new System.Windows.Thickness(0); SelectionMode = SelectionMode.Multiple; VirtualizingPanel.SetIsVirtualizing(this, true); VirtualizingPanel.SetVirtualizationMode(this, VirtualizationMode.Recycling); PreviewKeyDown += ListControl_PreviewKeyDown; }
/// <summary> /// Helper method which invalidate the underlying itemshost's measure and arrange /// </summary> /// <param name="withColumnVirtualization"> /// True to invalidate only when virtualization is on. /// False to invalidate only when virtualization is off. /// </param> private void InvalidateDataGridCellsPanelMeasureAndArrange(bool withColumnVirtualization) { // Invalidates measure and arrange if the flag and the virtualization // are either both true or both false. if (withColumnVirtualization == VirtualizingPanel.GetIsVirtualizing(this)) { InvalidateDataGridCellsPanelMeasureAndArrange(); } }
public void ScrollToEntity(int index) { VirtualizingPanel panel = EditorControlUtility.FindVisualChild <VirtualizingPanel>(EntityTree, ""); if (panel != null) { panel.BringIndexIntoViewPublic(index); } }
private static void BringIndexIntoView(this VirtualizingPanel virtualizingPanel, int index) { if (bringIndexIntoView == null) { bringIndexIntoView = Reflection <VirtualizingPanel> .GetMethod("BringIndexIntoView", Types.Array <int>(), @public : false); } bringIndexIntoView.Invoke(virtualizingPanel, new object[] { index }); }
partial void RefreshPartial() { if (VirtualizingPanel != null) { VirtualizingPanel.GetLayouter().Refresh(); InvalidateMeasure(); } }
public TreeList() { VirtualizingPanel.SetVirtualizationMode(this, VirtualizationMode.Recycling); IsSynchronizedWithCurrentItem = true; ItemsPanel = GetItemsPanelTemplate(); set_CanSelectMultiple(this, false); SizeChanged += OnSizeChanged; KeyDown += OnKeyDown; MouseLeftButtonDown += TreeList_MouseLeftButtonDown; }
protected override void OnElementChanged(ElementChangedEventArgs <ListView> e) { if (e.OldElement != null) // Clear old element event { e.OldElement.ItemSelected -= OnElementItemSelected; e.OldElement.ScrollToRequested -= OnElementScrollToRequested; var templatedItems = ((ITemplatedItemsView <Cell>)e.OldElement).TemplatedItems; templatedItems.CollectionChanged -= OnCollectionChanged; templatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged; } if (e.NewElement != null) { e.NewElement.ItemSelected += OnElementItemSelected; e.NewElement.ScrollToRequested += OnElementScrollToRequested; if (Control == null) // Construct and SetNativeControl and suscribe control event { var listView = new WList { DataContext = Element, ItemTemplate = (System.Windows.DataTemplate)System.Windows.Application.Current.Resources["CellTemplate"], Style = (System.Windows.Style)System.Windows.Application.Current.Resources["ListViewTemplate"] }; VirtualizingPanel.SetVirtualizationMode(listView, VirtualizationMode.Recycling); VirtualizingPanel.SetScrollUnit(listView, ScrollUnit.Pixel); SetNativeControl(listView); Control.MouseUp += OnNativeMouseUp; Control.KeyUp += OnNativeKeyUp; Control.TouchUp += OnNativeTouchUp; Control.StylusUp += OnNativeStylusUp; } // Suscribe element events var templatedItems = TemplatedItemsView.TemplatedItems; templatedItems.CollectionChanged += OnCollectionChanged; templatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged; // Update control properties UpdateItemSource(); UpdateHorizontalScrollBarVisibility(); UpdateVerticalScrollBarVisibility(); if (Element.SelectedItem != null) { OnElementItemSelected(null, new SelectedItemChangedEventArgs(Element.SelectedItem, -1)); } } base.OnElementChanged(e); }
public override void OnApplyTemplate() { base.OnApplyTemplate(); ControlGameView = Template.FindName("PART_ControlGameView", this) as Control; if (ControlGameView != null) { BindingTools.SetBinding(ControlGameView, Control.DataContextProperty, mainModel, nameof(DesktopAppViewModel.SelectedGameDetails)); } ListGames = Template.FindName("PART_ListGames", this) as ExtendedListBox; if (ListGames != null) { SetListGamesBinding(); BindingTools.SetBinding(ListGames, ExtendedListBox.SelectedItemProperty, mainModel, nameof(DesktopAppViewModel.SelectedGame), BindingMode.TwoWay); BindingTools.SetBinding(ListGames, ExtendedListBox.SelectedItemsListProperty, mainModel, nameof(DesktopAppViewModel.SelectedGamesBinder), BindingMode.TwoWay); ScrollToSelectedBehavior.SetEnabled(ListGames, true); if (!DesignerProperties.GetIsInDesignMode(this)) { ListGames.InputBindings.Add(new KeyBinding(mainModel.EditSelectedGamesCommand, mainModel.EditSelectedGamesCommand.Gesture)); ListGames.InputBindings.Add(new KeyBinding(mainModel.RemoveSelectedGamesCommand, mainModel.RemoveSelectedGamesCommand.Gesture)); ListGames.InputBindings.Add(new KeyBinding(mainModel.StartSelectedGameCommand, mainModel.StartSelectedGameCommand.Gesture)); } ListGames.SelectionMode = SelectionMode.Extended; VirtualizingPanel.SetCacheLengthUnit(ListGames, VirtualizationCacheLengthUnit.Item); VirtualizingPanel.SetCacheLength(ListGames, new VirtualizationCacheLength(5)); VirtualizingPanel.SetScrollUnit(ListGames, ScrollUnit.Pixel); VirtualizingPanel.SetIsVirtualizingWhenGrouping(ListGames, true); VirtualizingPanel.SetVirtualizationMode(ListGames, VirtualizationMode.Recycling); } ControlTemplateTools.InitializePluginControls( mainModel.Extensions, Template, this, SDK.ApplicationMode.Desktop, mainModel, $"{nameof(DesktopAppViewModel.SelectedGameDetails)}.{nameof(GameDetailsViewModel.Game)}.{nameof(GameDetailsViewModel.Game.Game)}"); }
public WPFGridView() { this.HorizontalGridLinesBrush = new SolidColorBrush(Colors.LightGray); this.VerticalGridLinesBrush = new SolidColorBrush(Colors.LightGray); this.CanUserAddRows = false; this.CanUserDeleteRows = false; this.HeadersVisibility = DataGridHeadersVisibility.Column; this.EnableColumnVirtualization = true; this.EnableRowVirtualization = true; VirtualizingPanel.SetVirtualizationMode(this, VirtualizationMode.Recycling); this.MouseDoubleClick += WPFGridView_MouseDoubleClick; this.DataContextChanged += this.WPFGridView_DataContextChanged; }
virtual internal void RealizeCore() { ItemsControlAutomationPeer itemsControlAutomationPeer = ItemsControlAutomationPeer; if (itemsControlAutomationPeer != null) { ItemsControl parent = itemsControlAutomationPeer.Owner as ItemsControl; if (parent != null) { if (parent.ItemContainerGenerator.Status == GeneratorStatus.ContainersGenerated) { if (AccessibilitySwitches.UseNetFx472CompatibleAccessibilityFeatures) { // Please note that this action must happen before the OnBringItemIntoView call because // that is a call that synchronously flushes out layout and we want these realized peers // cached before the UpdateSubtree kicks in OnLayoutUpdated. if (VirtualizingPanel.GetIsVirtualizingWhenGrouping(parent)) { itemsControlAutomationPeer.RecentlyRealizedPeers.Add(this); } } parent.OnBringItemIntoView(Item); } else { // The items aren't generated, try at a later time Dispatcher.BeginInvoke(DispatcherPriority.Loaded, (DispatcherOperationCallback) delegate(object arg) { if (AccessibilitySwitches.UseNetFx472CompatibleAccessibilityFeatures) { // Please note that this action must happen before the OnBringItemIntoView call because // that is a call that synchronously flushes out layout and we want these realized peers // cached before the UpdateSubtree kicks in OnLayoutUpdated. if (VirtualizingPanel.GetIsVirtualizingWhenGrouping(parent)) { itemsControlAutomationPeer.RecentlyRealizedPeers.Add(this); } } parent.OnBringItemIntoView(arg); return(null); }, Item); } } } }
/// <summary> /// Updates ItemsOwner object /// </summary> private void Initialize_ItemsOwner() { ItemsOwner = new VirtualizingStackPanel { Width = this.Width, Height = this.Height, FocusVisualStyle = null, }; VirtualizingPanel.SetIsVirtualizing(ItemsOwner, true); VirtualizingPanel.SetCacheLengthUnit(ItemsOwner, VirtualizationCacheLengthUnit.Item); VirtualizingPanel.SetCacheLength(ItemsOwner, new VirtualizationCacheLength(2)); VirtualizingPanel.SetVirtualizationMode(ItemsOwner, VirtualizationMode.Recycling); UpdateFrameworkElement(ItemsOwner, RenderSize, new Rect(RenderSize)); ChildrenGrid.Children.Add(ItemsOwner); }
/// <summary>Returns the UI Automation provider for the specified cell.</summary> /// <param name="row">The ordinal number of the row of interest.</param> /// <param name="column">The ordinal number of the column of interest.</param> /// <returns>The UI Automation provider for the specified cell.</returns> // Token: 0x060026B4 RID: 9908 RVA: 0x000B7CA0 File Offset: 0x000B5EA0 IRawElementProviderSimple IGridProvider.GetItem(int row, int column) { if (row < 0 || row >= ((IGridProvider)this).RowCount) { throw new ArgumentOutOfRangeException("row"); } if (column < 0 || column >= ((IGridProvider)this).ColumnCount) { throw new ArgumentOutOfRangeException("column"); } ListViewItem listViewItem = this._listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem; if (listViewItem == null) { VirtualizingPanel virtualizingPanel = this._listview.ItemsHost as VirtualizingPanel; if (virtualizingPanel != null) { virtualizingPanel.BringIndexIntoView(row); } listViewItem = (this._listview.ItemContainerGenerator.ContainerFromIndex(row) as ListViewItem); if (listViewItem != null) { this._listview.Dispatcher.Invoke(DispatcherPriority.Loaded, new DispatcherOperationCallback((object arg) => null), null); } } if (listViewItem != null) { AutomationPeer automationPeer = UIElementAutomationPeer.FromElement(this._listview); if (automationPeer != null) { AutomationPeer automationPeer2 = UIElementAutomationPeer.FromElement(listViewItem); if (automationPeer2 != null) { AutomationPeer eventsSource = automationPeer2.EventsSource; if (eventsSource != null) { automationPeer2 = eventsSource; } List <AutomationPeer> children = automationPeer2.GetChildren(); if (children.Count > column) { return(ElementProxy.StaticWrap(children[column], automationPeer)); } } } } return(null); }
private void CustomListView_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) { var isSlidingByPixel = false; var canContentScroll = ScrollViewer.GetCanContentScroll(this); if (canContentScroll) { var scrollUnit = VirtualizingPanel.GetScrollUnit(this); if (scrollUnit == ScrollUnit.Pixel) { isSlidingByPixel = true; } } if (isSlidingByPixel) { if (e.Delta > 0) { //向上 _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset - CustomPixelModeUnit); } else if (e.Delta < 0) { //向下 _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + CustomPixelModeUnit); } } else { if (e.Delta > 0) { //向上 _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset - CustomRowModeUnit); } else if (e.Delta < 0) { //向下 _scrollViewer.ScrollToVerticalOffset(_scrollViewer.VerticalOffset + CustomRowModeUnit); } } e.Handled = true; }
public TreeViewImpl(ITreeViewServiceImpl treeViewService, IThemeService themeService, IClassificationFormatMapService classificationFormatMapService, Guid guid, TreeViewOptions options) { Guid = guid; this.treeViewService = treeViewService; treeViewListener = options.TreeViewListener; classificationFormatMap = classificationFormatMapService.GetClassificationFormatMap(AppearanceCategoryConstants.UIMisc); classificationFormatMap.ClassificationFormatMappingChanged += ClassificationFormatMap_ClassificationFormatMappingChanged; foregroundBrushResourceKey = options.ForegroundBrushResourceKey ?? "TreeViewForeground"; sharpTreeView = new SharpTreeView(); sharpTreeView.SelectionChanged += SharpTreeView_SelectionChanged; sharpTreeView.CanDragAndDrop = options.CanDragAndDrop; sharpTreeView.AllowDrop = options.AllowDrop; sharpTreeView.AllowDropOrder = options.AllowDrop; VirtualizingPanel.SetIsVirtualizing(sharpTreeView, options.IsVirtualizing); VirtualizingPanel.SetVirtualizationMode(sharpTreeView, options.VirtualizationMode); AutomationPeerMemoryLeakWorkaround.SetInitialize(sharpTreeView, true); sharpTreeView.SelectionMode = options.SelectionMode; sharpTreeView.BorderThickness = new Thickness(0); sharpTreeView.ShowRoot = false; sharpTreeView.ShowLines = false; if (options.IsGridView) { sharpTreeView.SetResourceReference(ItemsControl.ItemContainerStyleProperty, SharpGridView.ItemContainerStyleKey); sharpTreeView.SetResourceReference(FrameworkElement.StyleProperty, "SharpTreeViewGridViewStyle"); } else { // Clear the value set by the constructor. This is required or our style won't be used. sharpTreeView.ClearValue(ItemsControl.ItemContainerStyleProperty); sharpTreeView.SetResourceReference(FrameworkElement.StyleProperty, typeof(SharpTreeView)); } sharpTreeView.GetPreviewInsideTextBackground = () => themeService.Theme.GetColor(ColorType.SystemColorsHighlight).Background; sharpTreeView.GetPreviewInsideForeground = () => themeService.Theme.GetColor(ColorType.SystemColorsHighlightText).Foreground; // Add the root at the end since Create() requires some stuff to have been initialized root = Create(options.RootNode ?? new TreeNodeDataImpl(new Guid(DocumentTreeViewConstants.ROOT_NODE_GUID))); sharpTreeView.Root = root.Node; }
private static void ResetVisualState(ContentPresenter objectToPrint, PrintCapabilities printCaps, bool wasVirtualized) { objectToPrint.Width = double.NaN; objectToPrint.UpdateLayout(); objectToPrint.LayoutTransform = new ScaleTransform(1, 1); Size size = new Size(printCaps.PageImageableArea.ExtentWidth, printCaps.PageImageableArea.ExtentHeight); objectToPrint.Measure(size); objectToPrint.Arrange(new Rect(new Point(printCaps.PageImageableArea.OriginWidth, printCaps.PageImageableArea.OriginHeight), size)); if (!wasVirtualized) { return; } var dg = objectToPrint.FindChild <DataGrid>(); dg.EnableRowVirtualization = true; dg.EnableColumnVirtualization = true; VirtualizingPanel.SetIsVirtualizing(dg, true); }
/// <summary> /// Reset scrollbar position of virtualizing panel if scrollBar becomes invisible /// </summary> /// <param name="listView"></param> public static void HandleScrollBarInvisible(this ListView listView) { ScrollViewer scrollView = UITools.FindVisualChild <ScrollViewer>(listView); DependencyPropertyDescriptor vertScrollbarVisibilityDescriptor = DependencyPropertyDescriptor.FromProperty( ScrollViewer.ComputedVerticalScrollBarVisibilityProperty, typeof(ScrollViewer)); vertScrollbarVisibilityDescriptor.AddValueChanged (scrollView, delegate { if (scrollView.ComputedHorizontalScrollBarVisibility == System.Windows.Visibility.Collapsed) { VirtualizingPanel panel = UITools.FindVisualChild <VirtualizingPanel>(listView); if (panel is IScrollInfo) { (panel as IScrollInfo).SetVerticalOffset(0); } } }); DependencyPropertyDescriptor horzScrollbarVisibilityDescriptor = DependencyPropertyDescriptor.FromProperty( ScrollViewer.ComputedHorizontalScrollBarVisibilityProperty, typeof(ScrollViewer)); horzScrollbarVisibilityDescriptor.AddValueChanged (scrollView, delegate { if (scrollView.ComputedHorizontalScrollBarVisibility == System.Windows.Visibility.Collapsed) { VirtualizingPanel panel = UITools.FindVisualChild <VirtualizingPanel>(listView); if (panel is IScrollInfo) { (panel as IScrollInfo).SetHorizontalOffset(0); } } }); }
private static bool LoadVirtualizedRows(ContentPresenter content, int rowCount) { DataGrid dg; if (!content.TryFindChild <DataGrid>(out dg)) { return(false); } if (dg == null) { return(false); } if (dg.Items.Count == 0) { return(false); } if (!dg.EnableRowVirtualization) { return(false); } dg.EnableRowVirtualization = false; dg.EnableColumnVirtualization = false; VirtualizingPanel.SetIsVirtualizing(dg, false); for (int i = 0; i < dg.Items.Count; i++) { dg.ScrollIntoView(dg.Items[i]); if (i == rowCount) { break; } } dg.ScrollIntoView(dg.Items[0]); return(true); }
/// <summary> /// 搜索条件更改回调 /// </summary> /// <param name="d"></param> /// <param name="e"></param> private static void OnSearchTextPropretyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { SearchableTextBox stb = d as SearchableTextBox; if (stb == null || !stb._canSearching) { return; } string searchKey = e.NewValue as string; if (string.IsNullOrEmpty(searchKey))//搜索关键字为空,不展示搜索popup { if (stb._popup != null) { stb._popup.IsOpen = false; } return; } if (stb.SearchItemsSource == null || stb.SearchItemsSource.Count == 0)//搜索源为空,显示无搜索结果 { if (stb._popup != null) { stb._popup.IsOpen = true; } if (stb._lstSearchResult != null) { stb._lstSearchResult.Visibility = Visibility.Collapsed; } return; } //根据关键字搜索匹配 IList <SearchModel> searchResultList = null; if (stb.SearchMethod != null) { searchResultList = stb.SearchMethod(searchKey, stb.SearchItemsSource); } else { searchResultList = stb.DefaultSearch(searchKey, stb.SearchItemsSource); } lock (stb) { stb.SearchResultCollection.Clear(); if (searchResultList != null && searchResultList.Count > 0) { foreach (SearchModel sm in searchResultList) { stb.SearchResultCollection.Add(sm); } } if (stb._popup != null) { stb._popup.IsOpen = true; } if (stb._lstSearchResult != null) { if (stb.SearchResultCollection.Count != 0) { stb._lstSearchResult.Visibility = Visibility.Visible; //每次重新搜索,从头开始展示 VirtualizingPanel virtualizingPanel = stb._lstSearchResult.GetItemsHost() as VirtualizingPanel; if (virtualizingPanel != null) { virtualizingPanel.CallEnsureGenerator(); virtualizingPanel.CallBringIndexIntoView(0); } ListBoxItem firstItem = (ListBoxItem)stb._lstSearchResult.ItemContainerGenerator.ContainerFromIndex(0); if (null != firstItem) { firstItem.UpdateLayout(); firstItem.BringIntoView(); } } else { stb._lstSearchResult.Visibility = Visibility.Collapsed; } } } }