本文整理汇总了C#中System.Windows.Input.TraversalRequest类的典型用法代码示例。如果您正苦于以下问题:C# TraversalRequest类的具体用法?C# TraversalRequest怎么用?C# TraversalRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraversalRequest类属于System.Windows.Input命名空间,在下文中一共展示了TraversalRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnPreviewKeyDown
private static void OnPreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
if (GetFocusNext((UIElement)sender))
{
TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
UIElement keyboardFocus = Keyboard.FocusedElement as UIElement;
if (keyboardFocus != null)
{
keyboardFocus.MoveFocus(tRequest);
}
}
else if (GetFocusedControl((UIElement)sender) != null)
{
var ctl = GetFocusedControl((UIElement)sender);
if (ctl != null && ctl is IInputElement)
{
FocusManager.SetFocusedElement(ctl, (IInputElement)ctl);
}
}
e.Handled = true;
}
}
示例2: TabIntoCore
protected override Boolean TabIntoCore(TraversalRequest request)
{
if (this.m_GotFocus != null)
{
this.m_GotFocus(this, EventArgs.Empty);
}
return true;
}
示例3: OnPreviewMouseLeftButtonDown
private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var row = sender as DataGridRow;
row.Focusable = true;
bool focused = row.Focus();
TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
if (elementWithFocus != null)
elementWithFocus.MoveFocus(request);
}
示例4: Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
FocusManager.SetFocusedElement(this, tb);
TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
UIElement keyboardFocus = Keyboard.FocusedElement as UIElement;
if (keyboardFocus != null)
{
keyboardFocus.MoveFocus(tRequest);
}
}
示例5: KeyUp_TextBox
void KeyUp_TextBox(object sender, KeyEventArgs e)
{
var tb = e.OriginalSource as TextBox;
if (tb == null)
{
return;
}
if (e.Key == Key.Return || e.Key == Key.Enter)
{
var req = new TraversalRequest(FocusNavigationDirection.Next);
tb.MoveFocus(req);
}
}
示例6: OnMoveFocus
private void OnMoveFocus(object sender, RoutedEventArgs e)
{
// Creating a FocusNavigationDirection object and setting it to a
// local field that contains the direction selected.
var focusDirection = _focusMoveValue;
// MoveFocus takes a TraveralReqest as its argument.
var request = new TraversalRequest(focusDirection);
// Gets the element with keyboard focus.
var elementWithFocus = Keyboard.FocusedElement as UIElement;
// Change keyboard focus.
elementWithFocus?.MoveFocus(request);
}
示例7: MoveToNextUIElement
private static void MoveToNextUIElement(KeyEventArgs e)
{
// Creating a FocusNavigationDirection object and setting it to a
// local field that contains the direction selected.
const FocusNavigationDirection focusDirection = FocusNavigationDirection.Next;
// MoveFocus takes a TraveralReqest as its argument.
var request = new TraversalRequest(focusDirection);
// Gets the element with keyboard focus.
var elementWithFocus = Keyboard.FocusedElement as UIElement;
// Change keyboard focus.
if (elementWithFocus == null) return;
if (elementWithFocus.MoveFocus(request)) e.Handled = true;
}
示例8: CreateDynamicEditingElement
protected override FrameworkElement CreateDynamicEditingElement(Entity curEntity)
{
var value = this.PropertyValue;
//支持两种属性类型:DateRange,String,所以这里使用这个变量进行分辨
var useDateRangeType = this.Meta.PropertyMeta.Runtime.PropertyType == typeof(DateRange);
var range = useDateRangeType ?
new DateRange(value as DateRange) :
DateRange.Parse(value != null ? value as string : string.Empty);
var control = new DateRangePropertyEditorControl(range);
control.Confirm += (oo, ee) =>
{
if (useDateRangeType)
{
var raw = value as DateRange;
raw.BeginValue = ee.Range.BeginValue;
raw.EndValue = ee.Range.EndValue;
}
else
{
this.PropertyValue = ee.Range.ToString();
}
};
control.KeyDown += (oo, ee) =>
{
if (ee.Key == Key.Enter)
{
FocusNavigationDirection focusDirection = FocusNavigationDirection.Next;
TraversalRequest request = new TraversalRequest(focusDirection);
control.MoveFocus(request);
}
};
this.AddReadOnlyComponent(control);
this.SetAutomationElement(control);
return control;
}
示例9: Merlin_DataContextChanged
void Merlin_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue is QueryEditorModel)
{
QueryEditorModel model = e.NewValue as QueryEditorModel;
model.BuildStartCommand.CanExecuteTargets += () => true;
model.BuildStartCommand.ExecuteTargets += (o) =>
{
// Source doesn't get updated for we need to move the
// focus out for the bind to the source.
TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
UIElement element = Keyboard.FocusedElement as UIElement;
if (element != null)
{
element.MoveFocus(request);
element.Focus();
}
};
}
}
示例10: Find_KeyUp
private void Find_KeyUp(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
ComboBox comboBox = ((ComboBox)sender);
if (comboBox.Text.Length > 0 && comboBox.Items != null && (comboBox.Items.Count == 0 || (string)comboBox.Items[0] != comboBox.Text))
{
comboBox.Items.Insert(0, comboBox.Text);
}
TraversalRequest tRequest = new TraversalRequest(FocusNavigationDirection.Next);
UIElement keyboardFocus = Keyboard.FocusedElement as UIElement;
if (keyboardFocus != null)
{
keyboardFocus.MoveFocus(tRequest);
}
}
else
{
mainWindow.FindNextStringOnPage(FindText.Text, false, true, this.MatchCase.IsChecked ?? true, this.RegexFind.IsChecked ?? true);
}
}
示例11: TextBox_TextChanged
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
TextBox textbox = (TextBox)sender;
byte octet;
if(!byte.TryParse(textbox.Text,out octet))
{
textbox.Text = "";
}
else
{
if (textbox.Text.Length == 3)
{
TraversalRequest request = new TraversalRequest(FocusNavigationDirection.Next);
request.Wrapped = true;
textbox.MoveFocus(request);
}
}
if(firstOctet.Text!="" && secondOctet.Text!="" && thirdOctet.Text!="" && fourthOctet.Text != "")
{
calculate();
}
IPCalculation ipc = new IPCalculation(null, 1);
}
示例12: Weekdays_PreviewKeyDown
private void Weekdays_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
Action<FocusNavigationDirection> moveFocus = focusDirection =>
{
e.Handled = true;
var request = new TraversalRequest(focusDirection);
var focusedElement = Keyboard.FocusedElement as CheckBox;
if (((string)focusedElement.Content == "SU" && request.FocusNavigationDirection == FocusNavigationDirection.Next))
{
Monday.Focus();
}
else if (((string)focusedElement.Content == "MO" && request.FocusNavigationDirection == FocusNavigationDirection.Previous))
{
Sunday.Focus();
}
else
{
focusedElement.MoveFocus(request);
}
};
if (e.Key == Key.Down)
{
moveFocus(FocusNavigationDirection.Previous);
}
else if (e.Key == Key.Up)
{
moveFocus(FocusNavigationDirection.Next);
}
if (e.Key == Key.Tab)
{
Sunday.Focus();
}
}
示例13: TabIntoCore
bool IKeyboardInputSink.TabInto(TraversalRequest request)
{
return TabIntoCore(request);
}
示例14: OnTabKeyDown
/// <summary>
/// Called when the tab key is pressed to perform focus navigation.
/// </summary>
private void OnTabKeyDown(KeyEventArgs e)
{
// When the end-user uses the keyboard to tab to another cell while the current cell
// is in edit-mode, then the next cell should enter edit mode in addition to gaining
// focus. There is no way to detect this from the focus change events, so the cell
// is going to handle the complete operation manually.
// The standard focus change method is being called here, so even if focus moves
// to something other than a cell, focus should land on the element that it would
// have landed on anyway.
DataGridCell currentCellContainer = CurrentCellContainer;
if (currentCellContainer != null)
{
bool wasEditing = currentCellContainer.IsEditing;
bool previous = ((e.KeyboardDevice.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift);
// Start navigation from the current focus to allow moveing focus on other focusable elements inside the cell
UIElement startElement = Keyboard.FocusedElement as UIElement;
ContentElement startContentElement = (startElement == null) ? Keyboard.FocusedElement as ContentElement : null;
if ((startElement != null) || (startContentElement != null))
{
e.Handled = true;
FocusNavigationDirection direction = previous ? FocusNavigationDirection.Previous : FocusNavigationDirection.Next;
TraversalRequest request = new TraversalRequest(direction);
// Move focus to the the next or previous tab stop.
if (((startElement != null) && startElement.MoveFocus(request)) ||
((startContentElement != null) && startContentElement.MoveFocus(request)))
{
// If focus moved to the cell while in edit mode - keep navigating to the previous cell
if (wasEditing && previous && Keyboard.FocusedElement == currentCellContainer)
{
currentCellContainer.MoveFocus(request);
}
// In case of grouping if a row level commit happened due to
// the previous focus change, the container of the row gets
// removed from the visual tree by the CollectionView,
// but we still hang on to a cell of that row, which will be used
// by the call to SelectAndEditOnFocusMove. Hence re-establishing the
// focus appropriately in such cases.
if (IsGrouping && wasEditing)
{
DataGridCell newCell = GetCellForSelectAndEditOnFocusMove();
if (newCell != null &&
newCell.RowDataItem == currentCellContainer.RowDataItem)
{
DataGridCell realNewCell = TryFindCell(ItemInfoFromContainer(newCell.RowOwner), newCell.Column);
// Forcing an UpdateLayout since the generation of the new row
// container which was removed earlier is done in measure.
if (realNewCell == null)
{
UpdateLayout();
realNewCell = TryFindCell(ItemInfoFromContainer(newCell.RowOwner), newCell.Column);
}
if (realNewCell != null && realNewCell != newCell)
{
realNewCell.Focus();
}
}
}
// When doing TAB and SHIFT+TAB focus movement, don't confuse the selection
// code, which also relies on SHIFT to know whether to extend selection or not.
SelectAndEditOnFocusMove(e, currentCellContainer, wasEditing, /* allowsExtendSelect = */ false, /* ignoreControlKey = */ true);
}
}
}
}
示例15: OnArrowKeyDown
//.........这里部分代码省略.........
}
else
{
nextDisplayIndex--;
while (nextDisplayIndex >= 0)
{
DataGridColumn column = ColumnFromDisplayIndex(nextDisplayIndex);
if (column.IsVisible)
{
break;
}
nextDisplayIndex--;
}
if (nextDisplayIndex < 0)
{
if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
{
nextDisplayIndex = InternalColumns.LastVisibleDisplayIndex;
}
else if (keyboardNavigationMode == KeyboardNavigationMode.Contained)
{
DependencyObject nextFocusTarget = keyboardNavigation.PredictFocusedElement(currentCellContainer, KeyToTraversalDirection(rtlKey),
treeViewNavigation:false, considerDescendants:false);
if (nextFocusTarget != null && keyboardNavigation.IsAncestorOfEx(this, nextFocusTarget))
{
Keyboard.Focus(nextFocusTarget as IInputElement);
}
return;
}
else // Continue, Local, None - move focus out of the datagrid
{
MoveFocus(new TraversalRequest(e.Key == Key.Left ? FocusNavigationDirection.Left : FocusNavigationDirection.Right));
return;
}
}
}
break;
case Key.Right:
if (controlModifier)
{
nextDisplayIndex = Math.Max(0, InternalColumns.LastVisibleDisplayIndex);
}
else
{
nextDisplayIndex++;
int columnCount = Columns.Count;
while (nextDisplayIndex < columnCount)
{
DataGridColumn column = ColumnFromDisplayIndex(nextDisplayIndex);
if (column.IsVisible)
{
break;
}
nextDisplayIndex++;
}
if (nextDisplayIndex >= Columns.Count)
{
if (keyboardNavigationMode == KeyboardNavigationMode.Cycle)
{
nextDisplayIndex = InternalColumns.FirstVisibleDisplayIndex;