public ComboBox() { DefaultStyleKey = typeof(ComboBox); SelectionChanged += new SelectionChangedEventHandler(ComboBox_SelectionChanged); LostFocus += new RoutedEventHandler(ComboBox_LostFocus); }
/// <summary> /// This method will be called when the AutoScrollToCurrentItem /// property was changed /// </summary> /// <param name="s">The sender (the ListBox)</param> /// <param name="e">Some additional information</param> public static void OnAutoScrollToCurrentItemChanged(DependencyObject s, DependencyPropertyChangedEventArgs e) { var listBox = s as ListBox; if (listBox == null) { return; } var listBoxItems = listBox.Items; if (listBoxItems == null) { return; } var newValue = (bool)e.NewValue; var autoScrollToCurrentItemWorker = new SelectionChangedEventHandler((s1, e2) => OnAutoScrollToCurrentItem(listBox, listBox.SelectedIndex)); if (newValue) { listBox.SelectionChanged += autoScrollToCurrentItemWorker; } else { listBox.SelectionChanged -= autoScrollToCurrentItemWorker; } }
private void BindVEAndSelectionChangedEvent(bool isVENeeded, SelectionChangedEventHandler UCselectionChange) { if (UCselectionChange != null) { xElementLocateByComboBox.SelectionChanged += UCselectionChange; } if (isVENeeded) { xElementLocateByComboBox.IsEditable = true; if (obj.GetType() == typeof(ActInputValue)) { GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(xElementLocateByComboBox, ComboBox.TextProperty, (ActInputValue)obj); } else { GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xElementLocateByComboBox, ComboBox.TextProperty, obj, AttrName); } } else { if (obj.GetType() == typeof(ActInputValue)) { GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(xElementLocateByComboBox, ComboBox.SelectedValueProperty, (ActInputValue)obj); } else { GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(xElementLocateByComboBox, ComboBox.SelectedValueProperty, obj, AttrName); } } }
private static void OnFocusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (DesignerProperties.GetIsInDesignMode(d)) { return; } UITabItem tabItem = d as UITabItem; if (tabItem != null) { TabControl tabControl = ControlHelper.FindVisualParent <TabControl>(tabItem); SelectionChangedEventHandler selectionChanged = (object sender, SelectionChangedEventArgs args) => { if (tabItem.IsSelected) { Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => { GetFocus(tabItem).Focus(); })); } }; if (e.NewValue != null) { tabControl.SelectionChanged += selectionChanged; } else { tabControl.SelectionChanged -= selectionChanged; } } }
/// <summary> /// 添加组合框 /// </summary> /// <param name="textName"></param> /// <param name="isIndependent"></param> public ComboBox GetComboBox(List <String> childTextName, int index, SelectionChangedEventHandler selectionChangedEvent) { ComboBox cb = new ComboBox(); cb.SelectedIndex = 0; cb.FontSize = 16; cb.BorderThickness = new Thickness(2); cb.Foreground = new SolidColorBrush(Colors.White); cb.Background = new SolidColorBrush(Color.FromRgb(43, 43, 43)); cb.BorderBrush = new SolidColorBrush(Color.FromRgb(31, 31, 31)); cb.Padding = new Thickness(10, 5, 10, 5); //cb.Margin = new Thickness(16, 0, 0, 0); foreach (String child in childTextName) { ComboBoxItem item = new ComboBoxItem(); item.SetResourceReference(StyleProperty, "ComboBoxItemStyle1"); item.Foreground = new SolidColorBrush(Colors.White); item.FontSize = 16; item.SetResourceReference(ContentProperty, child); cb.Items.Add(item); } cb.SelectedIndex = index; if (selectionChangedEvent != null) { cb.SelectionChanged += selectionChangedEvent; } return(cb); }
public CharacterSelect() { InitializeComponent(); lbClassSelectionChanged = new SelectionChangedEventHandler(_lbClasses_SelectionChanged); SubscribeEvents(); }
public static void BindCollection <T>(this ListBox list, ICollection <T> collection) { if (list.SelectedItems == collection) { throw new ArgumentException(); } list.SelectedItems.Clear(); foreach (var item in collection.ToArray()) { list.SelectedItems.Add(item); } SelectionChangedEventHandler onSelectionChanged = (s, e) => { foreach (var item in e.AddedItems) { if (!collection.Contains((T)item)) { collection.Add((T)item); } } foreach (var item in e.RemovedItems) { collection.Remove((T)item); } }; list.SelectionChanged += onSelectionChanged; // this needs to be done before "Unloaded" because at that point the items will have been all deselected MainWindow.Instance.LogicGrid.SelectedItemChanged += (s, e) => list.SelectionChanged -= onSelectionChanged; }
void UnitDefGrid_Loaded(object sender, RoutedEventArgs e) { var dataGrid = ((UnitDefsGrid)e.Source).Grid; var currentLogic = MainWindow.Instance.CurrentLogic; ObservableCollection <string> logicItemUnitList = null; if (currentLogic is UnitCreatedCondition) { logicItemUnitList = ((UnitCreatedCondition)currentLogic).Units; } else if (currentLogic is UnitFinishedCondition) { logicItemUnitList = ((UnitFinishedCondition)currentLogic).Units; } else if (currentLogic is UnitFinishedInFactoryCondition) { logicItemUnitList = ((UnitFinishedInFactoryCondition)currentLogic).Units; } else if (currentLogic is LockUnitsAction) { logicItemUnitList = ((LockUnitsAction)currentLogic).Units; } else if (currentLogic is UnlockUnitsAction) { logicItemUnitList = ((UnlockUnitsAction)currentLogic).Units; } if (logicItemUnitList == null) { return; } foreach (var unit in logicItemUnitList.ToArray()) { var unitInfo = MainWindow.Instance.Mission.Mod.UnitDefs.FirstOrDefault(u => u.Name == unit); if (unitInfo != null) { dataGrid.SelectedItems.Add(unitInfo); } } SelectionChangedEventHandler handler = (s, se) => { foreach (var item in se.AddedItems) { var info = (UnitInfo)item; logicItemUnitList.Add(info.Name); } foreach (var item in se.RemovedItems) { var info = (UnitInfo)item; logicItemUnitList.Remove(info.Name); } }; dataGrid.SelectionChanged += handler; // this needs to be done before "Unloaded" because at that point the items will have been all deselected MainWindow.Instance.LogicGrid.SelectedItemChanged += (s, ea) => dataGrid.SelectionChanged -= handler; }
/// <summary> /// Add a property to the grid, And set a custom event callback. /// </summary> /// <param name="PropName">Name of the property to add</param> /// <param name="ctype">The type of control that will be added to the grid</param> /// <param name="data">The data that will be inserted/set to the control</param> /// <param name="handler">the custom event handler</param> public void AddProperty(String PropName, ComboBox ctype, List <String> data, SelectionChangedEventHandler handler) { if (PropDictionary.ContainsKey(PropName)) { return; //avoid dict crash } int num = 0; //add label AddLabelProp(PropName, ref num); PropDictionary.Add(PropName, data); ctype.HorizontalAlignment = HorizontalAlignment.Left; ctype.VerticalAlignment = VerticalAlignment.Center; ctype.Margin = new Thickness(10, 2, 10, 2); ((ComboBox)ctype).ItemsSource = (List <String>)data; ctype.Height = 30; Grid.SetRow(ctype, num); Grid.SetColumn(ctype, 1); ctype.BringIntoView(); ctype.Tag = PropName; //used for EZ dictionary access later ((ComboBox)ctype).SelectionChanged += handler; ((ComboBox)ctype).SelectedIndex = 0; InnerPropGrid.Children.Add(ctype); //add the desired control type. }
public AbstractCorpo(List <AbstractViewItem> itens, SelectionChangedEventHandler selectionChanged = null) { if (itens.Count == 0) { return; } if (itens.Count == 1) { Content = itens.FirstOrDefault().Controls.FirstOrDefault(); } else { this.AddControl(new TabControl(), selectionChanged: selectionChanged); itens.ForEach(item => { this.AddControl(new TabItem { Header = item.Descricao }, controls: item.Controls); }); } selectionChanged?.Invoke(Content, null); }
/// <summary> /// This method will be called when the AutoScrollToCurrentItem /// property was changed /// </summary> /// <param name="s">The sender (the ListBox)</param> /// <param name="e">Some additional information</param> public static void OnAutoScrollToCurrentItemChanged(DependencyObject s, DependencyPropertyChangedEventArgs e) { var listView = s as ListView; if (listView != null) { var listBoxItems = listView.Items; if (listBoxItems != null) { var newValue = (bool)e.NewValue; var autoScrollToCurrentItemWorker = new SelectionChangedEventHandler((s1, e2) => { if (e2.AddedItems != null && e2.AddedItems.Count > 0) { OnAutoScrollToCurrentItem(listView, e2.AddedItems[0]); } }); if (newValue) { listView.SelectionChanged += autoScrollToCurrentItemWorker; } else { listView.SelectionChanged -= autoScrollToCurrentItemWorker; } } } }
public void SetSelectionChangedEventHandler(SelectionChangedEventHandler hdlr = null) { if (hdlr == null) { return; } bool onSelectionChanging = false; listView.SelectionChanged += (sender, e) => { if (onSelectionChanging == true) { return; } onSelectionChanging = true; //リスト更新中などに何度も走らないようにしておく。 //リストビュー自体に遅延実行があるので、イベントハンドラ外しても効果薄いため。 Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { hdlr(sender, e); onSelectionChanging = false; }), DispatcherPriority.ContextIdle); }; }
public Enuminator(String title, List <Entity> list, SelectionChangedEventHandler OnSelectionChanged) { InitializeComponent(); MainTitle.Text = title; listItems.SelectionChanged += OnSelectionChanged; listItems.ItemsSource = list; }
private void BindVEAndSelectionChangedEvent(bool isVENeeded, SelectionChangedEventHandler UCselectionChange) { if (UCselectionChange != null) { ComboBox.SelectionChanged += UCselectionChange; } if (isVENeeded) { Col.Width = new GridLength(22); VEButton.Visibility = Visibility.Visible; ComboBox.IsEditable = true; if (obj.GetType() == typeof(ActInputValue)) { GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(ComboBox, ComboBox.TextProperty, (ActInputValue)obj); } else { GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(ComboBox, ComboBox.TextProperty, obj, AttrName); } } else { if (obj.GetType() == typeof(ActInputValue)) { GingerCore.GeneralLib.BindingHandler.ActInputValueBinding(ComboBox, ComboBox.SelectedValueProperty, (ActInputValue)obj); } else { GingerCore.GeneralLib.BindingHandler.ObjFieldBinding(ComboBox, ComboBox.SelectedValueProperty, obj, AttrName); } } }
/// <summary> /// When the template is applied, this loads all the template parts /// </summary> public override void OnApplyTemplate() { base.OnApplyTemplate(); MouseButtonEventHandler mouseUpHandler = new MouseButtonEventHandler(this.ErrorsListBox_MouseLeftButtonUp); KeyEventHandler keyDownHandler = new KeyEventHandler(this.ErrorsListBox_KeyDown); SelectionChangedEventHandler selectionChangedHandler = new SelectionChangedEventHandler(this.ErrorsListBox_SelectionChanged); if (this._errorsListBox != null) { // If the ErrorsListBox was already set (due to multiple calls to OnApplyTemplate), unload the handlers first. this._errorsListBox.MouseLeftButtonUp -= mouseUpHandler; this._errorsListBox.KeyDown -= keyDownHandler; this._errorsListBox.SelectionChanged -= selectionChangedHandler; } this._errorsListBox = GetTemplateChild(PART_SummaryListBox) as ListBox; if (this._errorsListBox != null) { this._errorsListBox.MouseLeftButtonUp += mouseUpHandler; this._errorsListBox.KeyDown += keyDownHandler; this._errorsListBox.ItemsSource = this.DisplayedErrors; this._errorsListBox.SelectionChanged += selectionChangedHandler; } this._headerContentControl = GetTemplateChild(PART_HeaderContentControl) as ContentControl; this.UpdateDisplayedErrors(); this.UpdateCommonState(false); this.UpdateValidationState(false); }
public ComboBox CreateProjectList(IEnumerable <string> projects, SelectionChangedEventHandler onSelectionChanged) { var projectList = _template.CreateProjectList(_query.ProjectsName, _query.Project.Name, projects); projectList.SelectionChanged += onSelectionChanged; return(projectList); }
/// <summary> /// Show the list selector /// </summary> /// <param name="title">the title</param> /// <param name="itemsSource">the items source</param> /// <param name="selectedItem">the selected item</param> /// <param name="selectionChanged">the selection changed event handler</param> /// <param name="templateName">the template name</param> private void ShowListSelector( string title, IList itemsSource, object selectedItem, SelectionChangedEventHandler selectionChanged, string templateName) { if (this.ListSelector == null) { return; } var viewModel = this.DataContext as CaptionSettingsFlyoutViewModel; if (this.PageTitle != null) { this.PageTitle.Text = title.ToUpper(); } if (this.LayoutRoot != null) { this.ListSelector.ItemTemplate = this.LayoutRoot.Resources[templateName] as DataTemplate; if (this.ListSelector.ItemTemplate == null) { throw new InvalidOperationException("Could not find template in LayoutRoot: " + templateName); } } this.ListSelector.ItemsSource = itemsSource; //this.ListSelector.SelectedItem = selectedItem; this.ListSelector.Visibility = Visibility.Visible; this.ListSelector.SelectionChanged += selectionChanged; this.isListSelectorShown = true; }
public static void OnAutoScrollToSelectedItemChanged(DependencyObject s, DependencyPropertyChangedEventArgs e) { var listBox = s as ListBox; if (listBox != null) { var scrollToSelectionHandler = new SelectionChangedEventHandler( (sender, args) => ExecuteOnUIThread.InvokeAsync(() => { //listBox.UpdateLayout(); listBox.Focus(); // set focus to display selected item in blue instead of gray because list is not focused if (listBox.SelectedItem != null) { listBox.ScrollIntoView(listBox.SelectedItem); } }, DispatcherPriority.ContextIdle)); if ((bool)e.NewValue) { listBox.SelectionChanged += scrollToSelectionHandler; } else { listBox.SelectionChanged -= scrollToSelectionHandler; } } }
public override void OnApplyTemplate() { base.OnApplyTemplate(); var handler = new MouseButtonEventHandler(this.ErrorsListBox_MouseLeftButtonUp); var handler2 = new KeyEventHandler(this.ErrorsListBox_KeyDown); var handler3 = new SelectionChangedEventHandler(this.ErrorsListBox_SelectionChanged); if (this._errorsListBox != null) { this._errorsListBox.MouseLeftButtonUp -= handler; this._errorsListBox.KeyDown -= handler2; this._errorsListBox.SelectionChanged -= handler3; } this._errorsListBox = base.GetTemplateChild("SummaryListBox") as ListBox; if (this._errorsListBox != null) { this._errorsListBox.MouseLeftButtonUp += handler; this._errorsListBox.KeyDown += handler2; this._errorsListBox.ItemsSource = this.DisplayedErrors; this._errorsListBox.SelectionChanged += handler3; } this._headerContentControl = base.GetTemplateChild("HeaderContentControl") as ContentControl; this.UpdateDisplayedErrors(); this.UpdateCommonState(false); this.UpdateValidationState(false); }
public async Task Cycle() { if (this.ItemsSource != null) { var list = (IList)this.ItemsSource; if (list.Count == 0) { return; } SelectionChangedEventHandler handler = null; var tcs = new TaskCompletionSource <bool>(); handler = (s, e) => { tcs.SetResult(true); this.SelectionChanged -= handler; }; this.SelectionChanged += handler; this.SelectedIndex = (this.SelectedIndex + 1) % list.Count; await tcs.Task; await Task.Delay(500); var i = this.SelectedIndex; this.SelectedItem = null; var item = list[0]; list.RemoveAt(0); list.Add(item); this.SelectedIndex = i - 1; } else if (this.Items != null) { if (this.Items.Count == 0) { return; } SelectionChangedEventHandler handler = null; var tcs = new TaskCompletionSource <bool>(); handler = (s, e) => { tcs.SetResult(true); this.SelectionChanged -= handler; }; this.SelectionChanged += handler; this.SelectedIndex = (this.SelectedIndex + 1) % this.Items.Count; await tcs.Task; await Task.Delay(500); var i = this.SelectedIndex; this.SelectedItem = null; var item = this.Items[0]; this.Items.RemoveAt(0); this.Items.Add(item); this.SelectedIndex = i - 1; } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. /// This parameter is typically used to configure the page.</param> protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.NavigationMode != NavigationMode.Back) { IEnumerable <IGrouping <String, CommonObject> > commonObjects = null; var type = e.Parameter; if ("signs".Equals(type)) { commonObjects = AppLogic.Static.PreloadedContent.Signs.Data.GroupBy(sign => sign.num.Substring(0, sign.num.IndexOf('.')), sign => new CommonObject(sign)).ToArray(); } else if ("marks".Equals(type)) { commonObjects = AppLogic.Static.PreloadedContent.Marks.Data.GroupBy(mark => mark.num.Substring(0, mark.num.IndexOf('.')), mark => new CommonObject(mark)).ToArray(); } else { throw new NotImplementedException(String.Format("Unexpected type: {0}", e.Parameter)); } handler = (s, ev) => { if (ev.AddedItems.Count == 0) { return; } if (String.Empty.Equals(ev.AddedItems.Single())) { cmbSections.SelectedItem = ev.RemovedItems.Single(); } else { var commonObjectsArray = commonObjects.Single(commonObject => commonObject.Key.Equals(ev.AddedItems.Single().ToString())).ToArray(); cnvsSignsMarks.DataSource = null; cnvsSignsMarks.DataSource = new VirtualLinkedList <CommonObject[]>(new CommonObject[][] { commonObjectsArray }, (dataSource, current) => { return(dataSource.FirstOrDefault()); }, (dataSource, current) => { if (this.Frame.CanGoBack) { this.Frame.GoBack(); } return(null); }); } }; var itemsSource = commonObjects.Select(commonObject => commonObject.Key).ToArray(); if (itemsSource.Length < 6) { itemsSource = itemsSource.Concat(Enumerable.Range(0, 6 - itemsSource.Length).Select(i => String.Empty)).ToArray(); } this.cmbSections.ItemsSource = itemsSource; this.cmbSections.SelectionChanged += handler; this.cmbSections.SelectedItem = itemsSource.First(); } }
public RectangleSelection_ListViewBase(ListViewBase uiElement, Rectangle selectionRectangle, SelectionChangedEventHandler selectionChanged = null) { this.uiElement = uiElement; this.selectionRectangle = selectionRectangle; this.selectionChanged = selectionChanged; itemsPosition = new Dictionary <object, System.Drawing.Rectangle>(); InitEvents(null, null); }
/// <summary> /// Create a new tree view item /// </summary> /// <param name="parent">link to the parent</param> /// <param name="lazyLoadChildren">true to lazy load the children or false otherwise</param> public UIAutomatorNodeVM(INode node, SelectionChangedEventHandler eh) { _Model = node; _EH = eh; SelectionChanged += _EH; _Children = new NodeTree <UIAutomatorNodeVM>(); _LoadChildren(); }
public CategoriesPicker() { InitializeComponent(); Refresh(); SelectionChangedEvent = new SelectionChangedEventHandler(SelectCategory); cbxCategory.SelectionChanged += SelectionChangedEvent; Model.Windows.RefreshView += Refresh; }
/// <summary> /// Create a new tree view item /// </summary> /// <param name="parent">link to the parent</param> /// <param name="lazyLoadChildren">true to lazy load the children or false otherwise</param> public UIAutomatorNodeVM(INode node, SelectionChangedEventHandler eh) { _Model = node; _EH = eh; SelectionChanged += _EH; _Children = new NodeTree<UIAutomatorNodeVM>(); _LoadChildren(); }
private void PresentStatisticTypeOptions() { App.PopupSelectionService.Title = _localizedStrings.Prompts.SelectStatisticType; App.PopupSelectionService.ItemsSource = _statisticTypeOptions; App.PopupSelectionService.SelectionChanged += OnStatisticTypeOptionsSelectionChanged; _popupServiceSelectionChangedHandler = OnStatisticTypeOptionsSelectionChanged; App.PopupSelectionService.ShowPopup(); }
/// <summary> /// Called when the value of the SelectedItem property changes. /// </summary> /// <param name="oldValue">The old selected index.</param> /// <param name="newValue">The new value.</param> protected virtual void OnSelectedItemPropertyChanged(object oldValue, object newValue) { if (null == newValue) { // Unselect everything foreach (DataPoint dataPoint in ActiveDataPoints.Where(activeDataPoint => activeDataPoint.IsSelected)) { dataPoint.IsSelectedChanged -= OnDataPointIsSelectedChanged; dataPoint.IsSelected = false; dataPoint.IsSelectedChanged += OnDataPointIsSelectedChanged; } } else { // Find the corresponding Control DataPoint dataPoint = ActiveDataPoints.Where(activeDataPoint => activeDataPoint.DataContext.Equals(newValue)).FirstOrDefault(); if (null == dataPoint) { // None; clear SelectedItem try { _processingOnSelectedItemPropertyChanged = true; SelectedItem = null; // Clear newValue so the SelectionChanged event will be correct (or suppressed) newValue = null; } finally { _processingOnSelectedItemPropertyChanged = false; } } else { // Select it dataPoint.IsSelectedChanged -= OnDataPointIsSelectedChanged; dataPoint.IsSelected = true; dataPoint.IsSelectedChanged += OnDataPointIsSelectedChanged; } } // Fire SelectionChanged (if appropriate) SelectionChangedEventHandler handler = SelectionChanged; if ((null != handler) && !_processingOnSelectedItemPropertyChanged && (oldValue != newValue)) { IList oldValues = new List <object>(); if (oldValue != null) { oldValues.Add(oldValue); } IList newValues = new List <object>(); if (newValue != null) { newValues.Add(newValue); } handler(this, new SelectionChangedEventArgs(oldValues, newValues)); } }
public RectangleSelection_DataGrid(DataGrid uiElement, Rectangle selectionRectangle, SelectionChangedEventHandler selectionChanged = null) { this.uiElement = uiElement; this.selectionRectangle = selectionRectangle; this.selectionChanged = selectionChanged; itemsPosition = new Dictionary <object, System.Drawing.Rectangle>(); dataGridRows = new List <DataGridRow>(); InitEvents(null, null); }
void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { SelectionChangedEventHandler handler = SelectionChanged; if (handler != null) { handler(this, e); } }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// selectionchangedeventhandler.BeginInvoke(sender, e, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this SelectionChangedEventHandler selectionchangedeventhandler, Object sender, SelectionChangedEventArgs e, AsyncCallback callback) { if (selectionchangedeventhandler == null) { throw new ArgumentNullException("selectionchangedeventhandler"); } return(selectionchangedeventhandler.BeginInvoke(sender, e, callback, null)); }
private void OnElementItemsControlSelectChanged(object sender, SelectionChangedEventArgs e) { SelectionChangedEventHandler handler = SelectionChanged; if (handler != null) { handler(this, new SelectionChangedEventArgs(Selector.SelectionChangedEvent, e.RemovedItems, e.AddedItems)); } }
/// <summary> /// Standalone mode, use it for preview or something /// </summary> /// <param name="Vols"> The Volumes needed to be shown </param> /// <param name="SelectEvent"> EventHandler when an item is selected </param> private void Load( Volume[] Vols, SelectionChangedEventHandler SelectEvent = null ) { TOC = new TOCPane( Vols ); TOCContext.DataContext = TOC; if ( SelectEvent != null ) { TOCList.SelectionChanged += SelectEvent; } }
/// <summary> /// This method will be called when the AutoScrollToCurrentItem /// property was changed /// </summary> /// <param name="s">The sender (the ListBox)</param> /// <param name="e">Some additional information</param> public static void OnAutoScrollToCurrentItemChanged(DependencyObject s, DependencyPropertyChangedEventArgs e) { var listBox = s as ListBox; if (listBox == null) return; var listBoxItems = listBox.Items; if (listBoxItems == null) return; var newValue = (bool)e.NewValue; var autoScrollToCurrentItemWorker = new SelectionChangedEventHandler((s1, e2) => OnAutoScrollToCurrentItem(listBox, listBox.SelectedIndex)); if (newValue) listBox.SelectionChanged += autoScrollToCurrentItemWorker; else listBox.SelectionChanged -= autoScrollToCurrentItemWorker; }
private void OnPageDraftOptionSelected(object sender, SelectionChangedEventArgs args) { App.PopupSelectionService.SelectionChanged -= OnPageDraftOptionSelected; _popupServiceSelectionChangedHandler = null; int index = _draftListOptions.IndexOf(args.AddedItems[0] as string); switch (index) { case 0: //edit draft EditPage(); break; case 1: //delete draft DeletePageDraft(); break; } //reset selected index so we can re-select the original list item if we want to postsListBox.SelectedIndex = -1; }
public NavigationLongListSelector() { // Defines event handlers. SelectionChanged += new SelectionChangedEventHandler(OnSelectionChanged); }
protected virtual void Dispose(bool disposing) { if (disposed) { return; } // free any other managed objects here if (disposing) { foreach (UIAutomatorNodeVM child in _Children) { child.Dispose(); } SelectionChanged -= _EH; _EH = null; } // free any unmanaged objects here disposed = true; }
private StackPanel CreateStatusPanel(string id, string title, SelectionChangedEventHandler handler) { var child = CreatePanel(title); var statusbind = new Binding() { Source = data, Path = new PropertyPath("CpIsAvailable" + id), Mode = BindingMode.OneWay }; var selectedbind = new Binding() { Source = data, Path = new PropertyPath("CpSelectedIndex" + id), Mode = BindingMode.TwoWay }; var candidatesbind = new Binding() { Source = data, Path = new PropertyPath("CpCandidates" + id), Mode = BindingMode.OneWay }; var picker = CreatePicker(); picker.SetBinding(ListPicker.IsEnabledProperty, statusbind); picker.SetBinding(ListPicker.ItemsSourceProperty, candidatesbind); picker.SetBinding(ListPicker.SelectedIndexProperty, selectedbind); picker.SelectionChanged += handler; child.Children.Add(picker); return child; }
public ComboBox CreateProjectList(IEnumerable<string> projects, SelectionChangedEventHandler onSelectionChanged) { var projectList = _template.CreateProjectList(_query.ProjectsName, _query.Project.Name, projects); projectList.SelectionChanged += onSelectionChanged; return projectList; }
internal StackPanel InnerPanel(CardProperty cardProperty, Card thisCard, RoutedEventHandler onButtonChooseCardClick, RoutedEventHandler onPropertyTextBoxLostFocus, SelectionChangedEventHandler onPropertyComboBoxSelectionChanged, RoutedEventHandler onButtonNotSetClick) { // A StackPanel to hold the label and data controls for a single property. Each property gets one. // The enclosing WrapPanel (see XAML source) handles automatic layout on resize events. var panel = new StackPanel { Orientation = Orientation.Horizontal, Margin = new Thickness(6, 6, 0, 0), Tag = cardProperty }; var label = new Label { Content = cardProperty.Name, Background = _darkThemeBackground, FontWeight = FontWeights.ExtraBlack }; // Make labels for hidden properties italic. if (cardProperty.Hidden) label.FontStyle = FontStyles.Italic; panel.Children.Add(label); FrameworkElement uiElement; switch (cardProperty.IsManagedListOfScalars) { case false: { if (cardProperty.IsTeamValued) { uiElement = MakeComboBox(cardProperty); if (!cardProperty.IsTransitionOnly && !cardProperty.IsFormula) (uiElement as ComboBox).SelectionChanged += onPropertyComboBoxSelectionChanged; panel.Children.Add(uiElement); break; } uiElement = MakeTextBox(cardProperty, thisCard); if (!cardProperty.IsTransitionOnly && !cardProperty.IsFormula) { uiElement.LostFocus += onPropertyTextBoxLostFocus; } panel.Children.Add(uiElement); if (PropertyIsEditable(cardProperty) && cardProperty.IsCardValued) { // Add a 'click to choose' button Button a = MakeChooseCardButton(cardProperty); a.Click += onButtonChooseCardClick; a.Tag = uiElement; panel.Children.Add(a); var b = ValueNotSetButton(cardProperty, panel); b.Click += onButtonNotSetClick; panel.Children.Add(b); } break; } case true: { uiElement = MakeComboBox(cardProperty); (uiElement as ComboBox).SelectionChanged += onPropertyComboBoxSelectionChanged; panel.Children.Add(uiElement); break; } } return panel; }
/// <summary> /// Show the list selector /// </summary> /// <param name="title">the title</param> /// <param name="itemsSource">the items source</param> /// <param name="selectedItem">the selected item</param> /// <param name="selectionChanged">the selection changed event handler</param> /// <param name="templateName">the template name</param> private void ShowListSelector( string title, IList itemsSource, object selectedItem, SelectionChangedEventHandler selectionChanged, string templateName) { var viewModel = this.DataContext as CaptionSettingsFlyoutViewModel; this.PageTitle.Text = title; this.ListSelector.ItemsSource = itemsSource; this.ListSelector.SelectedItem = selectedItem; this.ListSelector.SelectionChanged += selectionChanged; this.ListSelector.ItemTemplate = this.Resources[templateName] as DataTemplate; VisualStateManager.GoToState(this, "ListShown", true); this.isListSelectorShown = true; }
public ColorComboBox() : base() { // A width of 120 seems to cover the longest string by itself (in English). this.Width = 148; this.Height = 26; // Create a DataTemplate for the items DataTemplate template = new DataTemplate(typeof(NamedColor)); // Create a FrameworkElementFactory based on StackPanel FrameworkElementFactory factoryStack = new FrameworkElementFactory(typeof(StackPanel)); factoryStack.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal); // Make that the root of the DataTemplate visual tree. template.VisualTree = factoryStack; // Create a FrameworkElementFactory based on Rectangle. FrameworkElementFactory factoryRectangle = new FrameworkElementFactory(typeof(Rectangle)); factoryRectangle.SetValue(Rectangle.WidthProperty, 16.0); factoryRectangle.SetValue(Rectangle.HeightProperty, 16.0); factoryRectangle.SetValue(Rectangle.MarginProperty, new Thickness(2)); factoryRectangle.SetValue(Rectangle.StrokeProperty, SystemColors.WindowTextBrush); factoryRectangle.SetValue(Rectangle.FillProperty, new Binding("Brush")); // Add it to the StackPanel. factoryStack.AppendChild(factoryRectangle); // Create a FrameworkElementFactory based on TextBlock. FrameworkElementFactory factoryTextBlock = new FrameworkElementFactory(typeof(TextBlock)); factoryTextBlock.SetValue(TextBlock.VerticalAlignmentProperty, VerticalAlignment.Center); factoryTextBlock.SetValue(TextBlock.TextProperty, new Binding("Name")); // Add it to the StackPanel. factoryStack.AppendChild(factoryTextBlock); // Set the ItemTemplate property to the template created above. this.ItemTemplate = template; // I'm setting this at the dropdown event, to save loading time. //this.ItemsSource = NamedColor.All; //this.DisplayMemberPath = "Name"; this.SelectedValuePath = "Color"; //DropDownOpened += new EventHandler(OnDropDownOpened); FillMyself(); SelectionChanged += new SelectionChangedEventHandler(OnSelectionChanged); }
private static void FillComboboxTags(System.Windows.Controls.ComboBox cb, IEnumerable source, SelectionChangedEventHandler changedEvent) { cb.SelectedValuePath = "Name"; cb.DisplayMemberPath = "Name"; cb.ItemsSource = null; cb.ItemsSource = source; cb.SelectionChanged += changedEvent; }
private void PresentPostOptions(bool isLocalDraft) { App.PopupSelectionService.Title = _localizedStrings.Prompts.PostActions; if (isLocalDraft) { App.PopupSelectionService.ItemsSource = _draftListOptions; _popupServiceSelectionChangedHandler = OnDraftOptionSelected; App.PopupSelectionService.SelectionChanged += OnDraftOptionSelected; } else { //No local draft, check the connection status first if (!App.isNetworkAvailable()) { Exception connErr = new NoConnectionException(); this.HandleException(connErr); return; } PostListItem postListItem = postsListBox.SelectedItem as PostListItem; if (null == postListItem) return; List<string> optionsList = new List<string>(_postListOptions); if (postListItem.Status != "draft" && postListItem.Status != "private") optionsList.Add(_localizedStrings.Options.PostOptions_SharePost); App.PopupSelectionService.ItemsSource = optionsList; _popupServiceSelectionChangedHandler = OnPostOptionSelected; App.PopupSelectionService.SelectionChanged += OnPostOptionSelected; } App.PopupSelectionService.ShowPopup(); }
void _positionIconButton_Click(object sender, EventArgs e) { // Show popup to choose where to position the media - at the beginning or end of the content. App.PopupSelectionService.Title = _localizedStrings.Prompts.MediaPlacement; App.PopupSelectionService.ItemsSource = _positionListOptions; App.PopupSelectionService.SelectionChanged += OnPositionOptionSelected; _popupServiceSelectionChangedHandler = OnPositionOptionSelected; //Keep a reference to the changes handler. It's only one for now, but preparing the code for future upgrade. App.PopupSelectionService.ShowPopup(); }
public XDataGrid() { SelectionChanged += new SelectionChangedEventHandler(DataGrid_SelectionChanged); PreviewMouseDown += new System.Windows.Input.MouseButtonEventHandler(DataGrid_PreviewMouseDown); MouseDoubleClick += new System.Windows.Input.MouseButtonEventHandler(DataGrid_MouseDoubleClick); }
public SelectionHandler() { sceh = ( s, e ) => { /* * La ListView ci notifica che la selezione * è cambiata. * * Per prima cosa ci sganciamo temporaneamente * dalla gestione delle notifiche in modo da non * innescare un meccanismo ricorsivo infinito */ this.Unwire(); var bag = this.GetSelectedItemsBag(); e.RemovedItems.Enumerate( obj => { var item = this.GetRealItem( obj ); if( bag.Contains( item ) ) { bag.Remove( item ); } } ); e.AddedItems.Enumerate( obj => { var item = this.GetRealItem( obj ); if( !bag.Contains( item ) ) { bag.Add( item ); } } ); this.Wire(); }; ncceh = ( s, e ) => { this.Unwire(); switch( e.Action ) { case NotifyCollectionChangedAction.Add: { this.AddToListViewSelection( e.NewItems ); } break; case NotifyCollectionChangedAction.Remove: { this.RemoveFromListViewSelection( e.OldItems ); } break; case NotifyCollectionChangedAction.Reset: { this.ClearListViewSelection(); this.AddToListViewSelection( this.GetSelectedItemsBag() ); } break; case NotifyCollectionChangedAction.Move: case NotifyCollectionChangedAction.Replace: //NOP break; default: throw new NotSupportedException(); } this.Wire(); }; lceh = ( s, e ) => { this.Unwire(); switch( e.ListChangedType ) { case ListChangedType.ItemAdded: { var bag = ( IEntityView )this.selectedItems; var item = bag[ e.NewIndex ]; this.AddToListViewSelection( new[] { item } ); } break; case ListChangedType.Reset: { this.ClearListViewSelection(); this.AddToListViewSelection( this.selectedItems ); } break; case ListChangedType.ItemDeleted: { this.RemoveFromListViewSelectionAtIndex( e.NewIndex ); } break; case ListChangedType.ItemChanged: case ListChangedType.ItemMoved: case ListChangedType.PropertyDescriptorAdded: case ListChangedType.PropertyDescriptorChanged: case ListChangedType.PropertyDescriptorDeleted: //NOP break; default: throw new NotSupportedException(); } this.Wire(); }; }
public ChannelSelector(ListView channelsListView, SelectionChangedEventHandler extChannelsListViewSelectionChanged) { this.channelsListView = channelsListView; this.channelsListView.SelectionChanged += extChannelsListViewSelectionChanged; }
private void OnStatisticTypeOptionsSelectionChanged(object sender, SelectionChangedEventArgs args) { App.PopupSelectionService.SelectionChanged -= OnStatisticTypeOptionsSelectionChanged; _popupServiceSelectionChangedHandler = null; if (1 < args.AddedItems.Count) return; string selection = args.AddedItems[0] as string; statisticTypeButton.Content = selection; }
public void AddCmbNamesHandler(SelectionChangedEventHandler handler) { cmbNames.SelectionChanged += handler; }
private void OnPostOptionSelected(object sender, SelectionChangedEventArgs args) { App.PopupSelectionService.SelectionChanged -= OnPostOptionSelected; _popupServiceSelectionChangedHandler = null; //recheck the connection status if (!App.isNetworkAvailable()) { Exception connErr = new NoConnectionException(); this.HandleException(connErr); return; } int index = 0; string selectedMenuLabel = args.AddedItems[0] as string; foreach (string value in App.PopupSelectionService.ItemsSource) { if (value == selectedMenuLabel) break; else index++; } switch (index) { case 0: //view post GetPostPermaLink(0); break; case 1: //view post comments ViewPostComments(); break; case 2: //edit post EditPost(); break; case 3: //delete post DeletePost(); break; case 4: //share post GetPostPermaLink(1); break; } //reset selected index so we can re-select the original list item if we want to postsListBox.SelectedIndex = -1; }
public void AddTabControl(SelectionChangedEventHandler handler) { MainWindowTabControl.SelectionChanged += handler; }
/// <summary> /// Show the list selector /// </summary> /// <param name="title">the title</param> /// <param name="itemsSource">the items source</param> /// <param name="selectedItem">the selected item</param> /// <param name="selectionChanged">the selection changed event handler</param> /// <param name="templateName">the template name</param> /// <param name="listLayoutMode">the list layout mode</param> private void ShowListSelector( string title, IList itemsSource, object selectedItem, SelectionChangedEventHandler selectionChanged, string templateName, LongListSelectorLayoutMode listLayoutMode) { if (this.ListSelector == null) { return; } this.ListSelector.LayoutMode = listLayoutMode; var viewModel = this.DataContext as CaptionSettingsFlyoutViewModel; if (this.PageTitle != null) { this.PageTitle.Text = title.ToUpper(CultureInfo.CurrentCulture); } this.ListSelector.ItemsSource = itemsSource; this.ListSelector.SelectedItem = selectedItem; this.ListSelector.SelectionChanged += selectionChanged; if (this.LayoutRoot != null) { this.ListSelector.ItemTemplate = this.LayoutRoot.Resources[templateName] as DataTemplate; if (this.ListSelector.ItemTemplate == null) { throw new InvalidOperationException("Could not find template in LayoutRoot: " + templateName); } } VisualStateManager.GoToState(this, "ListShown", true); this.isListSelectorShown = true; }