WPF讓button響應按鍵

在xmal中加入,響應回車鍵,其它鍵類似

    <Window.Resources>
        <RoutedUICommand x:Key="ClickCommand" Text="Text" />
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="{StaticResource ClickCommand}" Executed="EnterHandler" />
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Key="Enter" Command="{StaticResource ClickCommand}" />
    </Window.InputBindings>

 

在cs文件中加入函數

private void EnterHandler(object sender, RoutedEventArgs e)
        {
            //handle click event,加入想要實現的功能
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章