Click here to Skip to main content
15,887,302 members
Home / Discussions / WPF
   

WPF

 
GeneralMessage Removed Pin
12-May-09 7:55
professionalN_tro_P12-May-09 7:55 
GeneralRe: Custom Made Button Click event Pin
Mark Salsbery12-May-09 8:14
Mark Salsbery12-May-09 8:14 
GeneralMessage Removed Pin
12-May-09 8:24
professionalN_tro_P12-May-09 8:24 
GeneralRe: Custom Made Button Click event Pin
Mark Salsbery12-May-09 9:14
Mark Salsbery12-May-09 9:14 
GeneralMessage Removed Pin
12-May-09 9:19
professionalN_tro_P12-May-09 9:19 
GeneralRe: Custom Made Button Click event Pin
Mark Salsbery12-May-09 9:37
Mark Salsbery12-May-09 9:37 
GeneralMessage Removed Pin
12-May-09 9:48
professionalN_tro_P12-May-09 9:48 
GeneralRe: Custom Made Button Click event Pin
Mark Salsbery12-May-09 10:20
Mark Salsbery12-May-09 10:20 
Collin Jasnoch wrote:
I thought that is what I had posted...


Maybe....that doesn't mean I understood it Smile | :)

Anyway this is excellent, thanks. Now I see what's going on.

First of all, since your custom button is wrapped in a UserControl, its
events are no longer available at the UserControl level, so that's why
you can't get a Click event from the UserControl. This is one of the reasons
why a UserControl is the least flexible way to make a custom control....
UserControl is best suited for entirely self-contained controls.

There's a variety of ways around this - here's a few...

1) instead of wrapping a custom button in a UserControl
and instantiating a control of that UserControl type, just cut/copy the
button style that Blend created ("ButtonStyle1") to an appropriate place in
your app's resources, and anywhere you want an instance of your custom button,
instantiate a regular Button using that style, e.g.:




2) Leave it the way it is and add a public Click event to the CustomButton class.
This event should have the same signature as the ButtonBase class' Click event.
Add a Click event handler to the button in in the CustomButton user control.
In that handler, which will be in the CustomButton class, fire the event you added
to the CustomButton class....you'd be effectively just forwarding the event.


3) Go the full custom control route: Control Authoring Overview[^]


Method 3 is rarely necessary.

Method 2 has the limitations of a UserControl (e.g. users of the control can't
re-template the control to customize it) but it's the simplest to code.

Method 1 is also simple, and a very common way of customizing controls.


More info on options for customizing controls here: Control Authoring Overview[^]

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

QuestionObservableCollection Pin
RugbyLeague11-May-09 3:18
RugbyLeague11-May-09 3:18 
AnswerRe: ObservableCollection Pin
Pete O'Hanlon11-May-09 4:03
mvePete O'Hanlon11-May-09 4:03 
GeneralRe: ObservableCollection Pin
mark_w_11-May-09 4:18
mark_w_11-May-09 4:18 
GeneralRe: ObservableCollection Pin
Pete O'Hanlon11-May-09 4:26
mvePete O'Hanlon11-May-09 4:26 
GeneralRe: ObservableCollection Pin
mark_w_11-May-09 4:41
mark_w_11-May-09 4:41 
GeneralRe: ObservableCollection [modified] Pin
RugbyLeague11-May-09 5:02
RugbyLeague11-May-09 5:02 
AnswerRe: ObservableCollection Pin
Niladri_Biswas13-Jun-09 4:09
Niladri_Biswas13-Jun-09 4:09 
QuestionWPF - Namespaces Pin
mark_w_11-May-09 0:18
mark_w_11-May-09 0:18 
AnswerRe: WPF - Namespaces Pin
mark_w_11-May-09 5:33
mark_w_11-May-09 5:33 
AnswerRe: WPF - Namespaces Pin
Niladri_Biswas13-Jun-09 4:13
Niladri_Biswas13-Jun-09 4:13 
QuestionWPF performance problems in planning application Pin
h_c_d10-May-09 23:39
h_c_d10-May-09 23:39 
QuestionSize of a custom shape (DesiredSize) Pin
Pauwels Bart10-May-09 18:15
Pauwels Bart10-May-09 18:15 
AnswerRe: Size of a custom shape (DesiredSize) Pin
Pauwels Bart13-May-09 1:21
Pauwels Bart13-May-09 1:21 
QuestionQuick TextBox Question Pin
BlitzPackage10-May-09 11:46
BlitzPackage10-May-09 11:46 
AnswerRe: Quick TextBox Question Pin
Pete O'Hanlon10-May-09 21:38
mvePete O'Hanlon10-May-09 21:38 
GeneralRe: Quick TextBox Question Pin
BlitzPackage10-May-09 23:26
BlitzPackage10-May-09 23:26 
QuestionHow can I change a StaticResource by code behind Pin
existenc9-May-09 21:44
existenc9-May-09 21:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.