本文整理汇总了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);
}
}
}
}
示例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);
}
}
}