コード例 #1
0
        static void OnDataGridRowSelected(object sender, RoutedEventArgs e)
        {
            if (!object.ReferenceEquals(sender, e.OriginalSource))
            {
                return;
            }
            DataGridRow item = e.OriginalSource as DataGridRow;

            if (item != null)
            {
                item.BringIntoView();
            }
        }
コード例 #2
0
    static void OnDataGridRowSelected(object sender, RoutedEventArgs e)
    {
        // Only react to the Selected event raised by the TreeViewItem
        // whose IsSelected property was modified. Ignore all ancestors
        // who are merely reporting that a descendant's Selected fired.
        if (!Object.ReferenceEquals(sender, e.OriginalSource))
        {
            return;
        }
        DataGridRow item = e.OriginalSource as DataGridRow;

        if (item != null)
        {
            item.BringIntoView();
        }
    }
コード例 #3
0
        private void DeckDragEnter(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent("Card"))
            {
                e.Effects = DragDropEffects.None;
            }
            else
            {
                DataGridRow adornedRow = FindAncestor <DataGridRow>(e.OriginalSource as FrameworkElement); // used to place drop adorner
                DataGrid    grid       = (DataGrid)FindAncestor <Expander>(e.OriginalSource as FrameworkElement).Content;

                if (e.Effects == DragDropEffects.Copy)
                {
                    Expander          exp         = FindAncestor <Expander>(sender as FrameworkElement);
                    ObservableSection dropSection = (ObservableSection)((FrameworkElement)exp).DataContext;
                    var dragCard = e.Data.GetData("Card") as IMultiCard;
                    var element  = dropSection.Cards.FirstOrDefault(c => c.Id == dragCard.Id);
                    if (element != null) //i.e. card already in section
                    {
                        // Highlight the existing card
                        adornedRow = grid.ItemContainerGenerator.ContainerFromIndex(grid.Items.IndexOf(element)) as DataGridRow; // Move adorner to existing card
                        adornedRow.BringIntoView();
                        ShowAdorner(adornedRow, true);
                    }
                    else
                    {
                        e.Effects = DragDropEffects.All;
                    }
                }
                if (e.Effects == DragDropEffects.All)
                {
                    if (adornedRow != null && grid.Items.SortDescriptions.Count == 0)
                    {
                        ShowAdorner(adornedRow, false);
                    }
                    else if (grid != null)
                    {
                        ShowAdorner(grid, true);
                    }
                }
            }
        }