【问题标题】:Focus first button when there are two buttons in a window当窗口中有两个按钮时聚焦第一个按钮
【发布时间】:2017-07-06 04:08:11
【问题描述】:

我使用Window来显示一个对话框,对话框有两个按钮:确认和取消,但是取消按钮总是焦点,即使我设置了它的Focusable=False,而我想让确认按钮作为默认焦点,然后当按下回车键时,我可以执行确认处理程序。

  <Button x:Name="btnConfirm" Content="Confirm" HorizontalAlignment="Right" Margin="0,0,100,10" VerticalAlignment="Bottom" Width="75" Click="btnConfirm_Click" Focusable="True"/>
  <Button x:Name="btnCancel" Content="Cancel" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="75" IsDefault="True" Click="btnCancel_Click" Focusable="False"/> 

【问题讨论】:

    标签: wpf button focus


    【解决方案1】:

    您需要将IsDefault="True"btnCancel 移动到btnConfirm

    <Button x:Name="btnConfirm" ... IsDefault="True" ... />
    

    对于btnCancel,您可以设置IsCancel

    <Button x:Name="btnCancel" ... IsCancel="True" ... />
    

    【讨论】:

    • 谢谢,它有效。虽然取消按钮的初始状态也是焦点,与确认按钮相同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    相关资源
    最近更新 更多