AsyncReactiveCommandでWPFのお手軽ダブルクリック抑制
の記事を参考に、ボタンのダブルクリック抑制を入れました。
このボタンをキーボードのカーソルキーでも操作したいのですが、
ダブルクリック抑制が走るとそれ以降、キーボードのフォーカスがどこかへ行ってしまい、
キーボードでの操作ができなくなって困っています。
「キーボードの上下でボタンを選び、エンターキーでボタンを押す。それを何度も繰り返す。」
これをダブルクリック抑制とうまく同居させることは可能でしょうか?
xaml
1<Window x:Class="WpfApp4.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:WpfApp4" 7 mc:Ignorable="d" 8 Title="MainWindow" Height="300" Width="400"> 9 <Window.DataContext> 10 <local:MainWindowViewModel/> 11 </Window.DataContext> 12 <Grid> 13 <Button x:Name="button1" Content="Button1" HorizontalAlignment="Left" Margin="10,0,0,239" VerticalAlignment="Bottom" Width="372" Command="{Binding ButtonClickAsyncCommand1}"/> 14 <Button x:Name="button2" Content="Button2" HorizontalAlignment="Left" Margin="10,35,0,0" VerticalAlignment="Top" Width="372" Command="{Binding ButtonClickAsyncCommand2}"/> 15 </Grid> 16</Window>
cs
1using System.Windows; 2using System.Windows.Input; 3 4namespace WpfApp4 5{ 6 /// <summary> 7 /// MainWindow.xaml の相互作用ロジック 8 /// </summary> 9 public partial class MainWindow : Window 10 { 11 public MainWindow() 12 { 13 InitializeComponent(); 14 15 // 初期フォーカス設定 16 Loaded += (s, e) => { Keyboard.Focus(button1); }; 17 } 18 } 19}
cs
1using System.Threading.Tasks; 2using Reactive.Bindings; 3 4namespace WpfApp4 5{ 6 class MainWindowViewModel 7 { 8 public AsyncReactiveCommand ButtonClickAsyncCommand1 { get; } = new AsyncReactiveCommand(); 9 public AsyncReactiveCommand ButtonClickAsyncCommand2 { get; } = new AsyncReactiveCommand(); 10 11 public MainWindowViewModel() 12 { 13 ButtonClickAsyncCommand1.Subscribe(async _ => 14 { 15 await Task.Delay(500); 16 }); 17 ButtonClickAsyncCommand2.Subscribe(async _ => 18 { 19 await Task.Delay(500); 20 }); 21 } 22 } 23}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/07/28 08:27