Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting "AcceptButton" from WPF WindowsFormHost

I have a winforms usercontrol with multiple buttons in a WPF Control.

My usercontrol was previously hosted in a windows form and I was able to so

this.ParentForm.AcceptButton = this.btnSearch;

I'm trying to establish how to do similar on the usercontrol now that it is in the WindowsFormHost. The ParentForm property is null.

There are two things I would ideally like to achieve.

  1. AcceptButton behaviour (Enter key triggers button press)
  2. AcceptButton formatting - i.e. the winforms button has the alternate formatting for accept buttons applied.

Many thanks, Chris

like image 434
Chris Avatar asked Mar 25 '11 11:03

Chris


2 Answers

Set Button.IsCancel (Esc) or IsDefault (Enter) on the Buttons in the page.

Example:

<Button Content="Yes" Click="Yes_Button_Click" IsDefault="True"/>
<Button Content="No" Click="No_Button_Click" IsCancel="True"/>
like image 196
TrialAndError Avatar answered Oct 19 '22 00:10

TrialAndError


Set your default button's IsDefault property to true.

like image 44
farzad.moomeni Avatar answered Oct 18 '22 23:10

farzad.moomeni