本文整理汇总了C#中System.Windows.FrameworkElement.Focus方法的典型用法代码示例。如果您正苦于以下问题:C# FrameworkElement.Focus方法的具体用法?C# FrameworkElement.Focus怎么用?C# FrameworkElement.Focus使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.FrameworkElement
的用法示例。
在下文中一共展示了FrameworkElement.Focus方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareCellForEdit
protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs)
{
var textBox = editingElement as TextBox;
if (textBox != null)
textBox.MaxLength = MaxLength;
editingElement.Focus();
return null;
}
示例2: HITankController
/// <summary>
/// Input controller class constructor
/// </summary>
/// <param name="field"></param>
public HITankController(FrameworkElement field, Tank target)
: base(target)
{
field.Focus();
if (field != null)
{
this.Field = field;
this.Field.MouseMove += MousePositionChanged;
this.Field.MouseDown += Field_MouseDown;
}
}
示例3: FocusCore
private static void FocusCore(FrameworkElement element)
{
// System.Diagnostics.Debug.WriteLine("Focus core: " + element.DataContext);
if (!element.Focus())
{
element.Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() => element.Focus()));
}
#if DEBUG
// no good idea, seems to block sometimes
int i = 0;
while (i < 5)
{
if (element.IsFocused) return;
Thread.Sleep(100);
i++;
}
if (i >= 5)
{
}
#endif
}
示例4: SetFocus
private static void SetFocus(FrameworkElement element)
{
element.Focus();
var textboxElement = element as TextBox;
if (textboxElement != null)
{
int selectionEnd = textboxElement.Text.LastIndexOf('.');
if (selectionEnd == -1) {
selectionEnd = textboxElement.Text.Length;
}
textboxElement.Select(0, selectionEnd);
}
}
示例5: ExecuteElement
private static void ExecuteElement(FrameworkElement e)
{
IKeyTipControl cmd = e as IKeyTipControl;
if (cmd != null)
{
cmd.ExecuteKeyTip();
return;
}
CheckBox cb = e as CheckBox;
if (cb != null)
{
cb.IsChecked ^= true;
return;
}
ComboBox box = e as ComboBox;
if (box != null)
{
box.Focus();
box.IsDropDownOpen = true;
return;
}
if (e.Focusable) e.Focus();
}
示例6: AddSelectedElement
protected void AddSelectedElement(FrameworkElement child, bool focus = false)
{
if (!CanManipulateElement(child))
{
throw new InvalidOperationException("child");
}
if (AdornerLayer == null)
{
return;
}
if (focus)
{
child.Focus();
}
SelectedChilds.Add(new SelectedChild(child));
AdornerLayer.ClipToBounds = false;
AdornerLayer.Add(CreateAdornerForElement(child));
}
示例7: SetElementFocus
internal static void SetElementFocus(FrameworkElement Element, string SpecificElementName)
{
if (Element == null)
throw new ArgumentNullException("Element");
if (Element.Focusable)
{
Element.Focus();
Keyboard.Focus(Element);
}
else
{
//If the supplied element isn't focusable,
//try and find a child that is.
//Optionally, supply a child name to specify a specific control to hit
UIElement FirstFocusableChild = null;
if (string.IsNullOrEmpty(SpecificElementName))
FirstFocusableChild = Element.FindAllVisualChildren<UIElement>()
.Where((o) => o.Focusable)
.FirstOrDefault();
else
FirstFocusableChild = Element.FindAllVisualChildren<FrameworkElement>()
.Where((o) => o.Focusable && o.Name == SpecificElementName)
.FirstOrDefault();
if (FirstFocusableChild != null)
{
FirstFocusableChild.Focus();
Keyboard.Focus(FirstFocusableChild);
}
}
}
示例8: MapZoom
/// <summary>
/// Construct new MapZoom object that manages the RenderTransform of the given target object.
/// The target object must have a parent container.
/// </summary>
/// <param name="target">The target object we will be zooming.</param>
public MapZoom(FrameworkElement target)
{
this._container = target.Parent as FrameworkElement;
this._target = target;
_container.MouseMove += new MouseEventHandler(OnMouseMove);
_container.MouseWheel += new MouseWheelEventHandler(OnMouseWheel);
Keyboard.AddKeyDownHandler(_container, new KeyEventHandler(OnKeyDown));
Keyboard.AddKeyUpHandler(_container, new KeyEventHandler(OnKeyUp));
_container.Focusable = true;
_container.Focus();
// Try and reuse the existing TransformGroup if we can.
TransformGroup g = target.RenderTransform as TransformGroup;
if (g != null)
{
this._scale = g.Children.Count > 1 ? g.Children[0] as ScaleTransform : null;
this._translate = g.Children.Count > 0 ? g.Children[1] as TranslateTransform : null;
if (this._scale == null || this._translate == null)
{
g = null; // then the TransformGroup cannot be re-used
}
}
if (g == null)
{
g = new TransformGroup();
this._scale = new ScaleTransform(1, 1);
g.Children.Add(this._scale);
this._translate = new TranslateTransform();
g.Children.Add(this._translate);
target.RenderTransform = g;
}
this._zoom = this._newZoom = _scale.ScaleX;
// track changes made by the ScrolLViewer.
this._translate.Changed += new EventHandler(OnTranslateChanged);
this._scale.Changed += new EventHandler(OnScaleChanged);
}
示例9: tryToFocusAChild
void tryToFocusAChild(FrameworkElement element)
{
while (element.Focus() == false && element != null)
{
if (VisualTreeHelper.GetChildrenCount(element) > 0)
element = VisualTreeHelper.GetChild(element, 0) as FrameworkElement;
else
break;
}
}
示例10: AskToPrint
public static void AskToPrint( FrameworkElement ctrl
, string printJobDesc = "Scaled Visual")
{
PrintDialog print = new PrintDialog();
if (print.ShowDialog() != true) return;
PrintCapabilities capabilities = print.PrintQueue.GetPrintCapabilities(print.PrintTicket);
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / ctrl.ActualWidth,
capabilities.PageImageableArea.ExtentHeight / ctrl.ActualHeight);
//Transform oldTransform = ctrl.LayoutTransform;
ctrl.LayoutTransform = new ScaleTransform(scale, scale);
//Size oldSize = new Size(ctrl.ActualWidth, ctrl.ActualHeight);
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
ctrl.Measure(sz);
((UIElement)ctrl).Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight),
sz));
ctrl.Focus();
print.PrintVisual(ctrl, printJobDesc);
//ctrl.LayoutTransform = oldTransform;
//ctrl.Measure(oldSize);
//((UIElement)ctrl).Arrange(new Rect(new Point(0, 0),
// oldSize));
}