public static Dialog Show(object content) { var dialog = new Dialog { Content = content }; var window = VisualHelper.GetActiveWindow(); if (window != null) { var decorator = VisualHelper.GetChild <AdornerDecorator>(window); if (decorator != null) { if (decorator.Child != null) { decorator.Child.IsEnabled = false; } var layer = decorator.AdornerLayer; if (layer != null) { var container = new AdornerContainer(layer) { Child = dialog }; dialog._container = container; layer.Add(container); } } } return(dialog); }
private void ItemContainerGenerator_ItemsChanged(object sender, System.Windows.Controls.Primitives.ItemsChangedEventArgs e) { if (_scrollViewer == null) { _scrollViewer = VisualHelper.GetChild <ScrollViewer>(ListBoxChat); } _scrollViewer?.ScrollToBottom(); }
private void TabControl_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { if (e.AddedItems.Count == 0) { return; } if (e.AddedItems[0] is TabItem tabItem && VisualHelper.GetChild <ListBox>(tabItem.Content as DependencyObject) is ListBox listBox) { if (listBox.SelectedItem != null) { var item = listBox.SelectedItem; listBox.SelectedIndex = -1; listBox.SelectedItem = item; } } }
private void GroupItems(TabControl tabControl, DemoInfoModel demoInfo) { var listBox = VisualHelper.GetChild <ListBox>(tabControl); if (listBox == null) { return; } listBox.Items.GroupDescriptions?.Clear(); if (demoInfo.IsGroupEnabled) { Dispatcher.BeginInvoke(new Action(() => { listBox.Items.GroupDescriptions?.Add(new PropertyGroupDescription("GroupName")); }), DispatcherPriority.Background); } }
public void Close() { var window = VisualHelper.GetActiveWindow(); if (window != null) { var decorator = VisualHelper.GetChild <AdornerDecorator>(window); if (decorator != null) { if (decorator.Child != null) { decorator.Child.IsEnabled = true; } var layer = decorator.AdornerLayer; layer?.Remove(_container); } } }
/// <summary> /// Display context menu. /// </summary> /// <param name="sender">Object that raised the event.</param> /// <param name="e">Event arguments.</param> private void ContentControl_MouseDown(object sender, MouseButtonEventArgs e) { try { Control control = sender as Control; control.ContextMenu.Items.Clear(); TabControl tabControl = VisualHelper.GetAncestor <TabControl>(control); if (tabControl != null) { List <MenuItem> menuItems = new List <MenuItem>(); foreach (TabItem tabItem in tabControl.Items) { TextBlock textBlock = VisualHelper.GetChild <TextBlock>(tabItem.Header as DependencyObject); Image image = VisualHelper.GetChild <Image>(tabItem.Header as DependencyObject); if (textBlock != null && !String.IsNullOrWhiteSpace(textBlock.Text)) { object header = textBlock.Text; if (image != null) { StackPanel stack = new StackPanel(); stack.Orientation = Orientation.Horizontal; stack.Children.Add(new Image() { Source = image.Source, Height = image.Height, Width = image.Width, Margin = new Thickness(2) }); stack.Children.Add(new TextBlock() { Text = textBlock.Text, VerticalAlignment = System.Windows.VerticalAlignment.Center }); header = stack; } menuItems.Add(new MenuItem() { Header = header, Tag = tabItem }); } } foreach (MenuItem menuItem in menuItems.OrderBy(mi => mi.Header.ToString())) { control.ContextMenu.Items.Add(menuItem); } } if (control.ContextMenu.Items.Count > 0) { control.ContextMenu.IsEnabled = true; control.ContextMenu.PlacementTarget = control; control.ContextMenu.Placement = PlacementMode.Bottom; control.ContextMenu.IsOpen = true; } } catch (Exception err) { App.HandleException(err); } }