一、實現效果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; } }