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


C# FrameworkElement.Focus方法代码示例

本文整理汇总了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;
        }
开发者ID:Chandu-cuddle,项目名称:MaterialDesignInXamlToolkit,代码行数:10,代码来源:MaterialDataGridTextColumn.cs

示例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;
     }
 }
开发者ID:Vlad7,项目名称:TanksStory,代码行数:15,代码来源:HITankController.cs

示例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
		}
开发者ID:YoshihiroIto,项目名称:TreeViewEx,代码行数:22,代码来源:FocusHelper.cs

示例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);
     }
 }
开发者ID:johncapehart,项目名称:PsISEProjectExplorer,代码行数:13,代码来源:FocusExtensions.cs

示例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();
 }
开发者ID:apoorv-vijay-joshi,项目名称:FSE-2011-PDE,代码行数:23,代码来源:KeyTip.cs

示例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));
        }
开发者ID:Jo3-16,项目名称:FMA,代码行数:22,代码来源:LayoutCanvas.cs

示例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);
         }
     }
 }
开发者ID:ptownsend1984,项目名称:SampleApplications,代码行数:30,代码来源:Navigation.cs

示例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);
        }
开发者ID:WonderPanda,项目名称:Besieged,代码行数:46,代码来源:MapZoom.cs

示例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;
     }
 }
开发者ID:roederf,项目名称:wpfReferenceApp,代码行数:10,代码来源:AdornerPopup.cs

示例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));
        }
开发者ID:peterson1,项目名称:ErrH,代码行数:32,代码来源:ScaledVisualPrinter.cs


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