当前位置: 首页>>代码示例>>C#>>正文


C# DependencyObject.SetValueNoCallback方法代码示例

本文整理汇总了C#中System.Windows.DependencyObject.SetValueNoCallback方法的典型用法代码示例。如果您正苦于以下问题:C# DependencyObject.SetValueNoCallback方法的具体用法?C# DependencyObject.SetValueNoCallback怎么用?C# DependencyObject.SetValueNoCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.DependencyObject的用法示例。


在下文中一共展示了DependencyObject.SetValueNoCallback方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnSelectedItemPropertyChanged

        /// <summary>
        /// SelectedItemProperty property changed handler.
        /// </summary>
        /// <param name="d">DataGrid that changed its SelectedItem.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
        private static void OnSelectedItemPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DataGrid dataGrid = (DataGrid)d;

            if (!dataGrid.AreHandlersSuspended())
            {
                int rowIndex = (e.NewValue == null) ? -1 : dataGrid.DataConnection.IndexOf(e.NewValue);
                if (rowIndex == -1)
                {
                    // If the Item is null or it's not found, clear the Selection
                    if (!dataGrid.CommitEdit(DataGridEditingUnit.Row, true /*exitEditing*/))
                    {
                        // Edited value couldn't be committed or aborted
                        d.SetValueNoCallback(e.Property, e.OldValue);
                        return;
                    }

                    // Clear all row selections
                    dataGrid.ClearRowSelection(true /*resetAnchorSlot*/);
                }
                else
                {
                    dataGrid.SetValueNoCallback(DataGrid.SelectedIndexProperty, rowIndex);
                    int slot = dataGrid.SlotFromRowIndex(rowIndex);
                    if (slot != dataGrid.CurrentSlot)
                    {
                        if (!dataGrid.CommitEdit(DataGridEditingUnit.Row, true /*exitEditing*/))
                        {
                            // Edited value couldn't be committed or aborted
                            d.SetValueNoCallback(e.Property, e.OldValue);
                            return;
                        }
                        if (slot >= dataGrid.SlotCount || slot < -1)
                        {
                            if (dataGrid.DataConnection.CollectionView != null)
                            {
                                dataGrid.DataConnection.CollectionView.MoveCurrentToPosition(rowIndex);
                            }
                        }
                    }

                    int oldCurrentSlot = dataGrid.CurrentSlot;
                    try
                    {
                        dataGrid._noSelectionChangeCount++;
                        int columnIndex = dataGrid.CurrentColumnIndex;

                        if (columnIndex == -1)
                        {
                            columnIndex = dataGrid.FirstDisplayedNonFillerColumnIndex;
                        }
                        if (dataGrid.IsSlotOutOfSelectionBounds(slot))
                        {
                            dataGrid.ClearRowSelection(slot /*slotException*/, true /*resetAnchorSlot*/);
                            return;
                        }

                        dataGrid.UpdateSelectionAndCurrency(columnIndex, slot, DataGridSelectionAction.SelectCurrent, false /*scrollIntoView*/);
                    }
                    finally
                    {
                        dataGrid.NoSelectionChangeCount--;
                    }

                    if (!dataGrid._successfullyUpdatedSelection)
                    {
                        dataGrid.SetValueNoCallback(DataGrid.SelectedIndexProperty, oldCurrentSlot);
                        d.SetValueNoCallback(e.Property, e.OldValue);
                    }
                }
            }
        }
开发者ID:expanz,项目名称:expanz-Microsoft-XAML-SDKs,代码行数:77,代码来源:DataGrid.xaml.cs

示例2: OnSelectedIndexPropertyChanged

        /// <summary>
        /// SelectedIndexProperty property changed handler.
        /// </summary>
        /// <param name="d">DataGrid that changed its SelectedIndex.</param>
        /// <param name="e">DependencyPropertyChangedEventArgs.</param>
        private static void OnSelectedIndexPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DataGrid dataGrid = (DataGrid)d;
            if (!dataGrid.AreHandlersSuspended())
            {
                int index = (int)e.NewValue;

                // GetDataItem returns null if index is >= Count, we do not check newValue
                // against Count here to avoid enumerating through an Enumerable twice
                // Setting SelectedItem coerces the finally value of the SelectedIndex
                object newSelectedItem = (index < 0) ? null : dataGrid.DataConnection.GetDataItem(index);
                dataGrid.SelectedItem = newSelectedItem;
                if (dataGrid.SelectedItem != newSelectedItem)
                {
                    d.SetValueNoCallback(e.Property, e.OldValue);
                }
            }
        }
开发者ID:expanz,项目名称:expanz-Microsoft-XAML-SDKs,代码行数:23,代码来源:DataGrid.xaml.cs


注:本文中的System.Windows.DependencyObject.SetValueNoCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。