一、实现效果app
二、关注词ide
三、实现流程
自定义鼠标加载:this
// Setting CustomCursor to the CustomCursor.cur file. // This assumes the file CustomCursor.cur has been added to the project // as a resource. One way to accomplish this to add the following // ItemGroup section to the project file // // <ItemGroup> // <Content Include="CustomCursor.cur"> // <CopyToOutputDirectory>Always</CopyToOutputDirectory> // </Content> // </ItemGroup> _customCursor = new Cursor(Directory.GetCurrentDirectory() + @"\" + "CustomCursor.cur");
根据ComboBoxItem的项选择对应鼠标样式
设置显示区域.Cursor值,同时更新是否全局鼠标样式spa
case "WaitCursor": DisplayArea.Cursor = Cursors.Wait; break; case "Custom": DisplayArea.Cursor = _customCursor; break; } // If the cursor scope is set to the entire application // Use OverrideCursor to force the cursor for all elements if (_cursorScopeElementOnly == false) { Mouse.OverrideCursor = DisplayArea.Cursor; }
鼠标显示区域切换:code
private void CursorScopeSelected(object sender, RoutedEventArgs e) { var source = e.Source as RadioButton; if (source != null) { if (source.Name == "rbScopeElement") { // Setting the element only scope flag to true _cursorScopeElementOnly = true; // Clearing out the OverrideCursor. Mouse.OverrideCursor = null; } if (source.Name == "rbScopeApplication") { // Setting the element only scope flag to false _cursorScopeElementOnly = false; // Forcing the cursor for all elements. Mouse.OverrideCursor = DisplayArea.Cursor; } } }
一、实现效果:orm
二、关键词:blog
三、静态组织:
界面不需焦点区域(左侧)设置UIElment.Focusable=false
设置触发器实现:有焦点,则背景色改变。
四、实现流程:
加载时设置指定元素角度开始事件
private void OnLoaded(object sender, RoutedEventArgs e) { // Sets keyboard focus on the first Button in the sample. Keyboard.Focus(firstButton); }
焦点方向改变时(RadioButton事件):ip
private void OnFocusSelected(object sender, RoutedEventArgs e) { var source = e.Source as RadioButton; if (source != null) { _focusMoveValue = (FocusNavigationDirection) Enum.Parse( typeof (FocusNavigationDirection), (string) source.Content); } }
寻找将要应用下一个焦点的元素,并修改此元素属性ci
private void OnPredictFocus(object sender, RoutedEventArgs e) { DependencyObject predictionElement = null; var elementWithFocus = Keyboard.FocusedElement as UIElement; if (elementWithFocus != null) { // Only these four directions are currently supported // by PredictFocus, so we need to filter on these only. if ((_focusMoveValue == FocusNavigationDirection.Up) || (_focusMoveValue == FocusNavigationDirection.Down) || (_focusMoveValue == FocusNavigationDirection.Left) || (_focusMoveValue == FocusNavigationDirection.Right)) { // Get the element which would receive focus if focus were changed. predictionElement = elementWithFocus.PredictFocus(_focusMoveValue); var controlElement = predictionElement as Control; // If a ContentElement. if (controlElement != null) { controlElement.Foreground = Brushes.DarkBlue; controlElement.FontSize += 10; controlElement.FontWeight = FontWeights.ExtraBold; // Fields used to reset the UI when the mouse // button is released. _focusPredicted = true; _predictedControl = controlElement; } } } }
焦点移往下一个元素:
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); }
恢复下一个焦点元素的属性改变:
// Resets the UI after PredictFocus changes the UI. private void OnPredictFocusMouseUp(object sender, RoutedEventArgs e) { if (_focusPredicted) { _predictedControl.Foreground = Brushes.Black; _predictedControl.FontSize -= 10; _predictedControl.FontWeight = FontWeights.Normal; _focusPredicted = false; } }