List <item> selectedItems = new List <item>(); // list of items checked off

        private void CheckBoxChanged(object sender, RoutedEventArgs e)
        {
            CheckBox    checkBox    = (CheckBox)e.OriginalSource;                             // get checkbox selected
            DataGridRow dataGridRow = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox); // get row correspodning to that check box

            if ((bool)checkBox.IsChecked)                                                     // item is checked
            {
                // convert row to item and add to list
                selectedItems.Add((item)dataGridRow.DataContext);
                // put the id of the item in the id field so item can be updated, item last checked off
                id.Text = selectedItems[selectedItems.Count - 1].id.ToString();
            }
            else // item is unchecked
            {
                // get index of unchecked item in list and remove it
                int i = selectedItems.IndexOf((item)dataGridRow.DataContext);
                selectedItems.RemoveAt(i);
                if (selectedItems.Count == 0)
                {
                    // if no more items checked off clear id field
                    id.Text = "";
                }
                else
                {
                    // if more items checked off, take id of last one and put in id field so quantity can be updated
                    id.Text = selectedItems[selectedItems.Count - 1].id.ToString();
                }
            }
        }
Esempio n. 2
0
        private void sceneDot_MouseMove(object sender, MouseEventArgs e)
        {
            if (!isRectDragInProg)
            {
                return;
            }

            Border border = sender as Border;

            if (border != null)
            {
                var canvas   = VisualTreeHelpers.FindAncestor <Canvas>(border);
                var mousePos = e.GetPosition(canvas);

                double left = mousePos.X - (border.ActualWidth / 2);
                double top  = mousePos.Y - (border.ActualHeight / 2);
                border.Margin = new Thickness(left, top, 0, 0);

                var       imageWidth   = sceneImage.ActualWidth;
                var       imageHeight  = sceneImage.ActualHeight;
                SceneItem selectedItem = border.DataContext as SceneItem;
                selectedItem.XPos = ((border.Margin.Left + (border.Width / 2)) * 100) / imageWidth;
                selectedItem.YPos = ((border.Margin.Top + (border.Height / 2)) * 100) / imageHeight;
                ChangedItems.Add(selectedItem);
            }
        }
Esempio n. 3
0
        private static void ColumnHeader_Click(object sender, RoutedEventArgs e)
        {
            GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader;

            if (headerClicked != null && headerClicked.Column != null)
            {
                string propertyName = GetPropertyName(headerClicked.Column);
                if (!string.IsNullOrEmpty(propertyName))
                {
                    ListView listView = VisualTreeHelpers.FindAncestor <ListView>(headerClicked);;
                    if (listView != null)
                    {
                        ICommand command = GetCommand(listView);
                        if (command != null)
                        {
                            if (command.CanExecute(propertyName))
                            {
                                command.Execute(propertyName);
                            }
                        }
                        else if (GetAutoSort(listView))
                        {
                            ApplySort(listView.Items, propertyName, listView, headerClicked);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        private void element_GotFocus(object sender, RoutedEventArgs e)
        {
            if (sender is DependencyObject)
            {
                TextBox txt;

                if (sender is TextBox)
                {
                    txt = sender as TextBox;
                }
                else
                {
                    txt = VisualTreeHelpers.FindChild <TextBox>(sender as DependencyObject);
                }

                if (txt != null)
                {
                    txt.TextChanged -= txt_TextChanged;
                    txt.TextChanged += txt_TextChanged;

                    txt.SelectionStart  = 0;
                    txt.SelectionLength = txt.Text.Length;

                    if (txt.SelectionLength != 0)
                    {
                        selectAllOnTextChanged = true;
                    }
                }
            }

            SelectedElement = sender as UIElement;
        }
        private void CheckBoxChanged(object sender, RoutedEventArgs e)
        {
            CheckBox    checkBox    = (CheckBox)e.OriginalSource;
            DataGridRow dataGridRow = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox);

            if ((bool)checkBox.IsChecked)
            {
                if (selectedPunch == null)
                {
                    // store selected punch
                    selectedPunch = (punch)dataGridRow.DataContext;
                    checkedBox    = checkBox;
                }
                else
                {
                    //  if another box already checked, uncheck the most recently checked box without triggering function call
                    checkBox.Unchecked -= CheckBoxChanged;
                    checkBox.IsChecked  = false;
                    checkBox.Unchecked += CheckBoxChanged;
                    snackbar.MessageQueue.Enqueue("One selection at a time.");
                }
            }
            else
            {
                // it was unchecked
                selectedPunch = null;
                checkedBox    = null;
            }
        }
Esempio n. 6
0
        protected override Task OnVisibilityChanged()
        {
            if (ChannelSession.Chat.BotClient != null)
            {
                this.SendChatAsComboBox.ItemsSource = new List <string>()
                {
                    "Streamer", "Bot"
                };
                this.SendChatAsComboBox.SelectedIndex = 1;
            }
            else
            {
                this.SendChatAsComboBox.ItemsSource = new List <string>()
                {
                    "Streamer"
                };
                this.SendChatAsComboBox.SelectedIndex = 0;
            }

            ScrollViewer scrollViewer = VisualTreeHelpers.GetVisualChild <ScrollViewer>(this.ChatList);

            if (scrollViewer != null && scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight)
            {
                this.updateScrollingToLatest = true;
            }

            return(Task.FromResult(0));
        }
Esempio n. 7
0
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            var parentItemsControl = VisualTreeHelpers.FindAncestorOrSelf <ItemsControl>(container);

            if ((item != null) && (parentItemsControl != null))
            {
                var items = parentItemsControl.Items;
                if (items.IsEmpty)
                {
                    return(null);
                }

                // if only one element is present
                if (items.Count == 1)
                {
                    return(SingleElementTemplate);
                }

                var index = items.IndexOf(item);
                // if first item
                if (index == 0)
                {
                    return(FirstElementTemplate);
                }
                // if last item
                if (!items.IsEmpty && (index == items.Count - 1))
                {
                    return(LastElementTemplate);
                }
                return(MiddleElementTemplate);
            }

            return(null);
        }
Esempio n. 8
0
        private void chkCell_Unchecked(object sender, RoutedEventArgs e)
        {
            CheckBox        checkBox        = (CheckBox)e.OriginalSource;
            DataGridRow     dataGridRow     = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox);
            Data_Documentos data_Documentos = (Data_Documentos)dataGridRow.DataContext;

            data_Documentos.Selectable = false;
        }
        public void BtnRemoveAnimation_OnClick(object sender, RoutedEventArgs e)
        {
            AnimationViewModel animationViewModel = (AnimationViewModel)((Button)sender).DataContext;
            Button             dataContext        = (Button)sender;
            ItemsControl       itemsControl       = VisualTreeHelpers.FindAncestor <ItemsControl>(dataContext);

            ((StageViewModel)itemsControl.DataContext).Animations.Remove(animationViewModel);
        }
        private void Build_Click(object sender, RoutedEventArgs e)
        {
            IntPtr henv   = IntPtr.Zero;
            IntPtr hdbc   = IntPtr.Zero;
            short  result = 0;

            try
            {
                result = NativeMethods.SQLAllocEnv(out henv);
                if (!NativeMethods.SQL_SUCCEEDED(result))
                {
                    throw new ApplicationException(Properties.Resources.OdbcConnectionUIControl_SQLAllocEnvFailed);
                }

                result = NativeMethods.SQLAllocConnect(henv, out hdbc);
                if (!NativeMethods.SQL_SUCCEEDED(result))
                {
                    throw new ApplicationException(Properties.Resources.OdbcConnectionUIControl_SQLAllocConnectFailed);
                }

                string currentConnectionString = _connectionProperties.ToFullString();
                System.Text.StringBuilder newConnectionString = new System.Text.StringBuilder(1024);
                result = NativeMethods.SQLDriverConnect(hdbc, new WindowInteropHelper(Window.GetWindow(this)).Handle, currentConnectionString, (short)currentConnectionString.Length, newConnectionString, 1024, out short newConnectionStringLength, NativeMethods.SQL_DRIVER_PROMPT);
                if (!NativeMethods.SQL_SUCCEEDED(result) && result != NativeMethods.SQL_NO_DATA)
                {
                    // Try again without the current connection string, in case it was invalid
                    result = NativeMethods.SQLDriverConnect(hdbc, new WindowInteropHelper(Window.GetWindow(this)).Handle, null, 0, newConnectionString, 1024, out newConnectionStringLength, NativeMethods.SQL_DRIVER_PROMPT);
                }
                if (!NativeMethods.SQL_SUCCEEDED(result) && result != NativeMethods.SQL_NO_DATA)
                {
                    throw new ApplicationException(Properties.Resources.OdbcConnectionUIControl_SQLDriverConnectFailed);
                }
                else
                {
                    NativeMethods.SQLDisconnect(hdbc);
                }

                if (newConnectionStringLength > 0)
                {
                    Refresh_Click(sender, e);
                    _connectionProperties.Parse(newConnectionString.ToString());
                    VisualTreeHelpers.RefreshBindings(this);
                    passwordTextbox.Password = Password;
                }
            }
            finally
            {
                if (hdbc != IntPtr.Zero)
                {
                    NativeMethods.SQLFreeConnect(hdbc);
                }
                if (henv != IntPtr.Zero)
                {
                    NativeMethods.SQLFreeEnv(henv);
                }
            }
        }
Esempio n. 11
0
        private void ElementSquare_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var elementBlocks = VisualTreeHelpers.FindAllChildren <TextBlock>(sender as Border);

            SelectedElement = (elementBlocks.ToList()[0].Tag as Element);
            ElementSelected?.Invoke(sender, new ElementEventArgs {
                SelectedElement = this.SelectedElement
            });
        }
        private void AdvancedButton_Click(object sender, RoutedEventArgs e)
        {
            DataConnectionAdvancedDialog dataAdvancedDialog = new DataConnectionAdvancedDialog(ConnectionProperties);

            if (dataAdvancedDialog.ShowOkCancel())
            {
                VisualTreeHelpers.RefreshBindings(this);
            }
        }
Esempio n. 13
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            AssociatedObject.Loaded -= OnLoaded;
            ScrollViewer             = VisualTreeHelpers.FindChild <ScrollViewer>(AssociatedObject);

            if (ScrollViewer != null)
            {
                ScrollViewer.PreviewMouseWheel += OnPreviewMouseWheel;
            }
        }
Esempio n. 14
0
        private void AnimateCarousel()
        {
            var             carousel   = VisualTreeHelpers.FindChild <StackPanel>(ImageCarousel, "Carousel");
            Storyboard      storyboard = (this.Resources["CarouselStoryboard"] as Storyboard);
            DoubleAnimation animation  = storyboard.Children.First() as DoubleAnimation;

            Storyboard.SetTarget(animation, carousel);
            animation.To = -550 * _currentElement;
            storyboard.Begin();
        }
Esempio n. 15
0
        private void ChatList_LayoutUpdated(object sender, EventArgs e)
        {
            if (this.updateScrollingToLatest && this.MessageControls.Count > 0)
            {
                ScrollViewer scrollViewer = VisualTreeHelpers.GetVisualChild <ScrollViewer>(this.ChatList);
                scrollViewer.ScrollToEnd();

                this.updateScrollingToLatest = false;
            }
        }
        private void ProviderCombobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            locationLabel.IsEnabled            = false;
            locationTextBox.IsEnabled          = false;
            sqlAuthentication.IsChecked        = true;
            integraredSecRadioButton.IsEnabled = false;
            sqlAuthentication.IsEnabled        = false;
            usernameTextbox.IsEnabled          = false;
            usernameLabel.IsEnabled            = false;
            passwordLabel.IsEnabled            = false;
            passwordTextbox.IsEnabled          = false;
            savepasswordCheckbox.IsEnabled     = false;
            initialCatalogGroup.IsEnabled      = false;
            sqlAuthentication.IsChecked        = true;

            PropertyDescriptorCollection propertyDescriptors = TypeDescriptor.GetProperties(_connectionProperties);
            PropertyDescriptor           propertyDescriptor  = null;

            if ((propertyDescriptor = propertyDescriptors["Location"]) != null &&
                propertyDescriptor.IsBrowsable)
            {
                locationLabel.IsEnabled   = true;
                locationTextBox.IsEnabled = true;
            }
            if ((propertyDescriptor = propertyDescriptors["Integrated Security"]) != null &&
                propertyDescriptor.IsBrowsable)
            {
                integraredSecRadioButton.IsEnabled = true;
            }
            if ((propertyDescriptor = propertyDescriptors["User ID"]) != null &&
                propertyDescriptor.IsBrowsable)
            {
                usernameTextbox.IsEnabled   = true;
                usernameLabel.IsEnabled     = true;
                sqlAuthentication.IsEnabled = true;
            }
            if (_connectionProperties["Password"] != null)
            {
                passwordLabel.IsEnabled     = true;
                passwordTextbox.IsEnabled   = true;
                sqlAuthentication.IsEnabled = true;
            }
            if (_connectionProperties["Password"] != null &&
                (propertyDescriptor = propertyDescriptors["PersistSecurityInfo"]) != null &&
                propertyDescriptor.IsBrowsable)
            {
                savepasswordCheckbox.IsEnabled = true;
            }
            if ((propertyDescriptor = propertyDescriptors["Initial Catalog"]) != null &&
                propertyDescriptor.IsBrowsable)
            {
                initialCatalogGroup.IsEnabled = true;
            }
            VisualTreeHelpers.RefreshBindings(this);
        }
Esempio n. 17
0
        private void imageMovie_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var keyboard = VisualTreeHelpers.FindName <KeyboardControl>("keyboardControl", (sender as Image).Parent);

            if (keyboard == null)
            {
                return;
            }

            keyboard.SwitchKeyboardVisibility();
        }
Esempio n. 18
0
        protected override IList <FrameworkElement> GetCells()
        {
            var vte   = VisualTreeHelpers.GetVisualTreeEnumerator(Row, (v) => { return(v is VirtualTableCell); }, System.Windows.Input.FocusNavigationDirection.Next);
            var cells = new List <FrameworkElement>();

            while (vte.MoveNext())
            {
                cells.Add(vte.Current as VirtualTableCell);
            }
            return(cells);
        }
Esempio n. 19
0
        private static void HandleMouseHorizontalWheel([NotNull] Window handledWindow, IntPtr wParam)
        {
            if (handledWindow == null)
            {
                throw new ArgumentNullException(nameof(handledWindow));
            }

            int tilt = (short)Win32.HiWord(wParam);

            if (tilt == 0)
            {
                return;
            }

            IInputElement element = Mouse.DirectlyOver;

            if (element == null)
            {
                return;
            }

            if (!(element is UIElement))
            {
                element = VisualTreeHelpers.FindAncestor <UIElement>(element as DependencyObject);
            }
            if (element == null)
            {
                return;
            }

            // make sure the ancestor is this window
            if (!ReferenceEquals(VisualTreeHelpers.FindAncestor <Window>((DependencyObject)element), handledWindow))
            {
                return;
            }

            var ev = new MouseHorizontalWheelEventArgs(Mouse.PrimaryDevice, Environment.TickCount, tilt)
            {
                RoutedEvent = PreviewMouseHorizontalWheelEvent
                              //Source = handledWindow
            };

            // first raise preview
            element.RaiseEvent(ev);
            if (ev.Handled)
            {
                return;
            }

            // then bubble it
            ev.RoutedEvent = MouseHorizontalWheelEvent;
            element.RaiseEvent(ev);
        }
Esempio n. 20
0
        private void OnPreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            var treeViewItem = VisualTreeHelpers.FindAncestor <TreeViewItem>((DependencyObject)e.OriginalSource);

            if (treeViewItem == null)
            {
                return;
            }

            treeViewItem.IsSelected = true;
            e.Handled = true;
        }
Esempio n. 21
0
        //Evento uncheck para los items de la grilla.
        private void chkDiscontinue_Unchecked(object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.CheckBox checkBox = (System.Windows.Controls.CheckBox)e.OriginalSource;
            DataGridRow      dataGridRow = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox);
            ReporteDocumento produit     = (ReporteDocumento)dataGridRow.DataContext;

            if ((bool)checkBox.IsChecked == false)
            {
                produit.Check = false;
            }
            // e.Handled = true;
        }
Esempio n. 22
0
        private static void AddSortGlyph(GridViewColumnHeader columnHeader, ListSortDirection direction, ImageSource sortGlyph)
        {
            var textBlock = VisualTreeHelpers.FindChild <TextBlock>(columnHeader);

            AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(textBlock);

            adornerLayer.Add(
                new SortGlyphAdorner(
                    textBlock,
                    direction,
                    sortGlyph
                    ));
        }
Esempio n. 23
0
        /// <summary>
        /// Called when a data grid cell got focus.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private static void OnDataGridCellGotFocus(object sender, RoutedEventArgs e)
        {
            if (e.OriginalSource.GetType() == typeof(DataGridCell))
            {
                DataGrid dataGrid = (DataGrid)sender;
                dataGrid.BeginEdit(e);

                Control control = VisualTreeHelpers.FindChild <Control>(e.OriginalSource as DataGridCell);
                if (control != null)
                {
                    control.Focus();
                }
            }
        }
Esempio n. 24
0
        private void SetFocusOnFirstButton()
        {
            var firstButton = VisualTreeHelpers.FindVisualChild <Button>(AnswerButtons.ItemContainerGenerator.ContainerFromIndex(0));

            if (firstButton != null)
            {
                FocusManager.SetFocusedElement(AnswerButtons, firstButton);
                firstButton.Dispatcher.BeginInvoke((Action) delegate
                {
                    firstButton.Focus();
                    Keyboard.Focus(firstButton);
                }, DispatcherPriority.Input);
            }
        }
Esempio n. 25
0
 private void NavigateAction(string url)
 {
     if (url.StartsWith("#"))
     {
         var element = VisualTreeHelpers.FindChild <UIElement>(stack, string.Concat(url.Skip(1)));
         scrollViewer.ScrollToVerticalOffset(element.TranslatePoint(new Point(0, 0), stack).Y);
     }
     else
     {
         var nextPage = AllPages.Single(x => x.Path == url);
         onNavigating(nextPage);
         NavigationService?.Navigate(nextPage);
     }
 }
Esempio n. 26
0
        //Evento check para los items de la grilla.
        private void chkDiscontinue_Checked(object sender, RoutedEventArgs e)
        {
            //Obtener el elemento seleccionado en la grilla.
            System.Windows.Controls.CheckBox checkBox = (System.Windows.Controls.CheckBox)e.OriginalSource;
            //Obtner la fila seleccionada y el objeto asociado.
            DataGridRow      dataGridRow = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox);
            ReporteDocumento doc         = (ReporteDocumento)dataGridRow.DataContext;

            if ((bool)checkBox.IsChecked)
            {
                doc.Check = true;
            }
            //e.Handled = true;
        }
Esempio n. 27
0
        private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            var checkBox    = (CheckBox)e.OriginalSource;
            var dataGridRow = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox);

            if (dataGridRow == null)
            {
                return;
            }

            var item = dataGridRow.DataContext as AddonToInstall;

            item.Install = checkBox.IsChecked ?? false;
        }
        //Evento de cambio de estado en el checkbox check
        private void chkDiscontinue_Checked(object sender, RoutedEventArgs e)
        {
            //Obtener elemento seleccionado.
            System.Windows.Controls.CheckBox checkBox = (System.Windows.Controls.CheckBox)e.OriginalSource;
            //Obtener objeto asociado al elemento seleccionado
            DataGridRow    dataGridRow = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox);
            ReporteResumen resumen     = (ReporteResumen)dataGridRow.DataContext;

            if ((bool)checkBox.IsChecked)
            {
                resumen.Check = true;
            }
            e.Handled = true;
        }
Esempio n. 29
0
        //Evento uncheck para cada item del listado.
        private void chkDiscontinue_Unchecked(object sender, RoutedEventArgs e)
        {
            //Obtener el elemento seleccionado.
            System.Windows.Controls.CheckBox checkBox = (System.Windows.Controls.CheckBox)e.OriginalSource;
            //Obtener la fila seleccionada y objeto asociado.
            DataGridRow    dataGridRow = VisualTreeHelpers.FindAncestor <DataGridRow>(checkBox);
            ReporteEmpresa comprobante = (ReporteEmpresa)dataGridRow.DataContext;

            if ((bool)checkBox.IsChecked == false)
            {
                comprobante.Check = false;
            }
            e.Handled = true;
        }
 private void ConStrTextBox_LostFocus(object sender, RoutedEventArgs e)
 {
     try
     {
         _connectionProperties.Parse(conStrTextBox.Text.Trim());
         VisualTreeHelpers.RefreshBindings(this);
         passwordTextbox.Password = Password;
     }
     catch (ArgumentException ex)
     {
         MessageBox.Show(ex.Message, Properties.Resources.Error_Label, MessageBoxButton.OK, MessageBoxImage.Error);
         UpdateConnectionString();
     }
 }