private void SampleSitesList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                var currentSampleSite = (SampleSitesGroup)item.DataContext;
                System.Diagnostics.Process.Start(currentSampleSite.SampleSite.siteURL);
            }
        }
Beispiel #2
0
        public static DependencyObject GetPlacementItem(this ItemsControl lb, Point?pt = null)
        {
            if (lb == null)
            {
                return(null);
            }
            var element = lb.InputHitTest((Point)(pt ?? Mouse.GetPosition(lb))) as DependencyObject;

            return(element == null ? null : lb.ContainerFromElement(element));
        }
Beispiel #3
0
        private ListBoxItem GetClickedListBoxItem(ItemsControl itemsControl, DependencyObject dependencyObject)
        {
            if (itemsControl == null || dependencyObject == null)
            {
                return(null);
            }
            var item = ItemsControl.ContainerFromElement(itemsControl, dependencyObject) as ListBoxItem;

            return(item);
        }
Beispiel #4
0
        /// <summary>
        /// RoutedEventArgsのOriginalSourceから、ItemsContolのアイテムのコンテナとなるエレメントを取得
        /// </summary>
        /// <param name="self"></param>
        /// <param name="eventArgs"></param>
        /// <returns></returns>
        public static FrameworkElement GetItemContainerFromRoutedEvent(this ItemsControl self, RoutedEventArgs eventArgs)
        {
            if (!(eventArgs.OriginalSource is UIElement element))
            {
                return(null);
            }
            var container = self.ContainerFromElement(element);

            return(container as FrameworkElement);
        }
        private void ListBoxComponents_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(ListBoxComponents, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                DeleteProduct(item.Content.ToString());
                ListOut();
            }
        }
        /// <summary>
        /// Handles the <see cref="Control.MouseDoubleClick"/> event for a <see
        /// cref="ListViewItem"/> of the "Image File" <see cref="ListView"/>.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="MouseButtonEventArgs"/> object containing event data.</param>
        /// <remarks><para>
        /// <b>OnFileActivate</b> shows an error message if the <see cref="ImageFile.Bitmap"/>
        /// property of the double-clicked item in the "Image File" list view is a null reference.
        /// </para><para>
        /// Otherwise, <b>OnFileActivate</b> displays an independent form containing a <see
        /// cref="ScrollViewer"/> that shows the image file bitmap.</para></remarks>

        private void OnFileActivate(object sender, MouseButtonEventArgs args)
        {
            args.Handled = true;

            // retrieve double-clicked item, if any
            var source = args.OriginalSource as DependencyObject;
            var item   = ItemsControl.ContainerFromElement(FileList, source) as ListViewItem;

            if (item == null)
            {
                return;
            }

            // retrieve corresponding image file, if any
            ImageFile file = item.Content as ImageFile;

            if (file == null)
            {
                return;
            }

            // abort if no image file bitmap present
            if (file.Bitmap == null)
            {
                string message = String.Format(ApplicationInfo.Culture,
                                               Global.Strings.DialogImageError, file.Path);

                MessageBox.Show(MainWindow.Instance, message,
                                Global.Strings.TitleImageError, MessageBoxButton.OK, MessageBoxImage.Error);

                return;
            }

            Window window = null;

            try {
                // show image file bitmap in separate window
                window       = new ShowImage(file.Bitmap);
                window.Title = file.Path;
                window.Icon  = MainWindow.Instance.Icon;
                window.Show();
            }
            catch (Exception e) {
                string message = String.Format(ApplicationInfo.Culture,
                                               Global.Strings.DialogImageError, file.Path);

                MessageDialog.Show(MainWindow.Instance, message,
                                   Global.Strings.TitleImageError, e, MessageBoxButton.OK, Images.Error);

                if (window != null)
                {
                    window.Close();
                }
            }
        }
        private void PlaceholdersListBox_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                // ListBox item clicked - do some cool things here
                selectedField = GetField(item.Content.ToString());
                SetFieldDataPreview();
            }
        }
Beispiel #8
0
        private void ListBox_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                grid_Materia.Visibility = Visibility.Visible;
                ((LogViewModelNav)DataContext).MateriaActual = item.Content.ToString();
                _materiaActual = item.Content.ToString();
            }
        }
Beispiel #9
0
        private void imagesOfGameClicked(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                PictureWindow pictureWindow = new PictureWindow();
                pictureWindow.picture.Source = new BitmapImage(new Uri(item.Content.ToString(), UriKind.Absolute));
                pictureWindow.ShowDialog();
            }
        }
        private void Row_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            // Ensure row was clicked and not empty space
            var row = ItemsControl.ContainerFromElement((DataGrid)sender,
                                                        e.OriginalSource as DependencyObject) as DataGridRow;

            if (row == null)
            {
                return;
            }
        }
Beispiel #11
0
        private void listBox_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(listBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                // ListBox item clicked - do some cool things here
                ProcessRows(this.treeView, TOCTable, item.Content.ToString());
            }
            ProcessServices(listBox, TOCTable);
        }
Beispiel #12
0
        private void FileSelection(object sender, MouseButtonEventArgs e)
        {
            var Item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (Item != null)
            {
                FormatFile(Item.Content.ToString());
                Output.Text = TargetText;
                RandIgnore  = FileCollection.Items.IndexOf(Item);
            }
        }
        private void demandListPreview_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                var currentDemand = (Demand)item.DataContext;
                MainTabItem.AddChildUserControl(new ShowDemandContent(MainTabItem, currentDemand));
                //  MainTabItem.AddChildUserControl(new DemandContent(MainTabItem, currentDemand));
            }
        }
Beispiel #14
0
        private void DgRecipesGrid_OnMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            // Ensure row was clicked and not empty space
            var row = ItemsControl.ContainerFromElement((DataGrid)sender,
                e.OriginalSource as DependencyObject) as DataGridRow;

            if (row == null) return;

            Recipe recipe = row.DataContext as Recipe;
            this.TbSelectedRecipeId.Text = recipe.Id.ToString();
        }
Beispiel #15
0
 // A left click opens the selected directory in the gallery
 private void DirectoryTreeList_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (ItemsControl.ContainerFromElement(sender as ListView, e.OriginalSource as DependencyObject) is
         ListViewItem item)
     {
         DirectoryTreeList.SelectedItem = item;
         string[] folder =
         { _originFolder.GetAllShownFolders()[DirectoryTreeList.SelectedIndex].GetFolderPath() };
         CreateNewContext(folder);
     }
 }
Beispiel #16
0
        private void PeerList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(peerList, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                _ = peer.SetPeer((item.DataContext as PeerInfo).Id);
                peerList.IsEnabled = false;
                // ListBox item clicked - do some cool things here
            }
        }
Beispiel #17
0
        private void MessageListPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            ListBox     lb   = (ListBox)sender;
            ListBoxItem item = (ListBoxItem)ItemsControl.ContainerFromElement(lb, (DependencyObject)e.OriginalSource);

            if (item != null)
            {
                int index = lb.ItemContainerGenerator.IndexFromContainer(item);
                ((MainViewModel)DataContext).ClearMessage(index);
            }
        }
Beispiel #18
0
        private void DataGridQuestionsClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

            if (row != null)
            {
                DataRowView drv = row.Item as DataRowView;
                DataTable   dt  = proxy.GetAnswersDataTableByQuestionId(Convert.ToInt32(drv["id"]));
                DataGridAnswers.DataContext = dt.DefaultView;
            }
        }
Beispiel #19
0
        private void CheckBox_Checked(object sender, RoutedEventArgs e)
        {
            if (sender is CheckBox chbx)
            {
                switch (chbx.Name)
                {
                case "chbx_h_erase":
                    if (!m_selectone)
                    {
                        m_selectall = true;
                        foreach (AskingFile file in ListSource)
                        {
                            file.Overwrite = true;
                        }
                        m_selectall = false;
                    }
                    break;

                case "chbx_h_num":
                    if (!m_selectone)
                    {
                        m_selectall = true;
                        foreach (AskingFile file in ListSource)
                        {
                            file.Number = true;
                        }
                        m_selectall = false;
                    }
                    break;

                case "chbx_erase":
                    ((ItemsControl.ContainerFromElement(AskList, chbx) as ListViewItem).Content as AskingFile).Number = false;
                    chbx_h_num.IsChecked = false;
                    if (!m_selectall && ListSource.Where(af => af.Overwrite).Count() == ListSource.Count)
                    {
                        m_selectone            = true;
                        chbx_h_erase.IsChecked = true;
                        m_selectone            = false;
                    }
                    break;

                case "chbx_num":
                    ((ItemsControl.ContainerFromElement(AskList, chbx) as ListViewItem).Content as AskingFile).Overwrite = false;
                    chbx_h_erase.IsChecked = false;
                    if (!m_selectall && ListSource.Where(af => af.Number).Count() == ListSource.Count)
                    {
                        m_selectone          = true;
                        chbx_h_num.IsChecked = true;
                        m_selectone          = false;
                    }
                    break;
                }
            }
        }
Beispiel #20
0
        private void ListBox_OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var item =
                ItemsControl.ContainerFromElement(TestListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null && item.IsSelected)
            {
                TestListBox.SelectedIndex = -1;
                e.Handled = true;
            }
        }
        private void datagridHoldInvoice_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

            if (row == null)
            {
                return;
            }

            _delegateInvoiceOpen.DynamicInvoke();
        }
        /// <summary>
        /// 指定アイテムを所有するコンテナを取得する。
        /// </summary>
        private FrameworkElement GetItemContainer(ItemsControl itemsControl, DependencyObject item)
        {
            //パラメータ確認
            if ((itemsControl == null) || (item == null))
            {
                return(null);
            }

            //コンテナを取得
            return(itemsControl.ContainerFromElement(item) as FrameworkElement);
        }
Beispiel #23
0
        private void ListBox_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement((ItemsControl)sender, (DependencyObject)e.OriginalSource) as ListBoxItem;

            if (item == null)
            {
                return;
            }
            var series = (LineSeries)item.Content;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                series.Visibility = series.Visibility == Visibility.Visible
                    ? Visibility.Hidden
                    : Visibility.Visible;
            }
            else if (e.RightButton == MouseButtonState.Pressed)
            {
                int index = -1;
                if (YRadioButton.IsChecked.Value)
                {
                    index = YSeries.IndexOf(series);
                }
                else if (XRadioButton.IsChecked.Value)
                {
                    index = XSeries.IndexOf(series);
                }
                else if (YSpeedRadioButton.IsChecked.Value)
                {
                    index = YSpeedSeries.IndexOf(series);
                }
                else
                {
                    index = XSpeedSeries.IndexOf(series);
                }
                if (index == YSeries.Count - 1)
                {
                    return;
                }
                YSeries.RemoveAt(index);
                XSeries.RemoveAt(index);
                YSpeedSeries.RemoveAt(index);
                XSpeedSeries.RemoveAt(index);
                AnimCanvas.Children.Remove(Ellipsies[index]);
                AnimCanvas.Children.Remove(Polylines[index]);
                Ellipsies.RemoveAt(index);
                Polylines.RemoveAt(index);
                YAnimations.RemoveAt(index);
                XAnimations.RemoveAt(index);
                Parameters.RemoveAt(index);
                UpdateAnimation = true;
                DataChanged     = true;
            }
        }
        private void _recentlyUsedResolutionsList_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(_recentlyUsedResolutionsList, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                SetNewResolutionControlsWithValues((Resolution)item.Content);
                _recentlyUsedResolutionsFlyout.Hide();
                PerformHotSampling();
            }
        }
Beispiel #25
0
        private void VisitGrid_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var row = ItemsControl.ContainerFromElement((DataGrid)sender,
                                                        e.OriginalSource as DependencyObject) as DataGridRow;

            if (row == null)
            {
                e.Handled = true;
                return;
            }
        }
Beispiel #26
0
        private void MarketDataDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridRow row = ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) as DataGridRow;

            if (row == null)
            {
                return;
            }

            Clipboard.SetText((row.Item as MarketItem).Product.Name);
        }
        private ToolboxItem GetToolboxItem(UIElement dragElement)
        {
            ToolboxItem      item          = null;
            ContentPresenter itemPresenter = _itemsControl.ContainerFromElement(dragElement) as ContentPresenter;

            if (itemPresenter != null)
            {
                item = itemPresenter.Content as ToolboxItem;
            }
            return(item);
        }
        private void smartphonesListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var item =
                ItemsControl.ContainerFromElement(smartphonesListBox, e.OriginalSource as DependencyObject) as
                ListBoxItem;

            if (item != null)
            {
                var imageWindow = new ImageWindow((item.Content as Smartphone).PictureLocation);
                imageWindow.Show();
            }
        }
Beispiel #29
0
        // If the types of the dragged data and ItemsControl's source are compatible,
        // there are 3 situations to have into account when deciding the drop target:
        // 1. mouse is over an items container
        // 2. mouse is over the empty part of an ItemsControl, but ItemsControl is not empty
        // 3. mouse is over an empty ItemsControl.
        // The goal of this method is to decide on the values of the following properties:
        // targetItemContainer, insertionIndex and isInFirstHalf.
        private void DecideDropTarget(DragEventArgs e)
        {
            int    targetItemsControlCount = _target.Items.Count;
            object draggedItem             = e.Data.GetData(ItemsControlDragDrop.Format.Name);

            if (IsDropDataTypeAllowed(draggedItem))
            {
                if (targetItemsControlCount > 0)
                {
                    _hasVerticalOrientation = HasVerticalOrientation(_target.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement);
                    _targetItemContainer    = _target.ContainerFromElement((DependencyObject)e.OriginalSource) as FrameworkElement;

                    if (_targetItemContainer != null)
                    {
                        Point positionRelativeToItemContainer = e.GetPosition(_targetItemContainer);
                        _isInFirstHalf  = IsInFirstHalf(_targetItemContainer, positionRelativeToItemContainer, _hasVerticalOrientation);
                        _insertionIndex = _target.ItemContainerGenerator.IndexFromContainer(_targetItemContainer);

                        if (!_isInFirstHalf)
                        {
                            _insertionIndex++;
                        }
                    }
                    else
                    {
                        _targetItemContainer = _target.ItemContainerGenerator.ContainerFromIndex(targetItemsControlCount - 1) as FrameworkElement;
                        _isInFirstHalf       = false;
                        _insertionIndex      = targetItemsControlCount;
                    }
                }
                else
                {
                    _targetItemContainer = null;
                    _insertionIndex      = 0;
                }

                var droppingItem = new CanDropItemEventArgs(draggedItem, _insertionIndex);
                _target.RaiseEvent(droppingItem);

                if (!droppingItem.CanDrop)
                {
                    _targetItemContainer = null;
                    _insertionIndex      = -1;
                    e.Effects            = DragDropEffects.None;
                }
            }
            else
            {
                _targetItemContainer = null;
                _insertionIndex      = -1;
                e.Effects            = DragDropEffects.None;
            }
        }
        private void PlaceholdersListBox_OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            var item = ItemsControl.ContainerFromElement(sender as ListBox, e.OriginalSource as DependencyObject) as ListBoxItem;

            if (item != null)
            {
                ipLbl.Content        = item.Content;
                usernameLbl.Content  = ips[item.Content.ToString()][0];
                emailLbl.Content     = ips[item.Content.ToString()][1];
                cloudSizeLbl.Content = ips[item.Content.ToString()][2];
            }
        }