tags:

views:

212

answers:

2

Hello!

I have a window, in which i have many controls, UserControls or controls derived from other controls (and grids and frames).

It works fine if i DON'T add any event to ANY of the controls i have in my window (in XAML). I have many other events that don't cause this, but if i add a new event. It will crash.

Example:

This is the control i would like to add my event to:

<con:MyControl Content="Hello" Grid.Column="3" Width="90"/>

So, i change it into:

<con:MyControl Content="Hello" Grid.Column="3" Width="90" Click="Hello_Click"/>

The application compiles...

But then, this happens:

'Set connectionId threw an exception.' Line number '53' and line position '22'.

InnerException:

{"Unable to cast object of type 'System.Windows.Controls.Button' to type 'MyNamespace.MyClass.MyControl'."}

If i now remove

Click="Hello_Click"

It works perfectly fine!

A: 

Can you provide more information about you MyControl? It needs some details about the control's implementation to answer your question.

viky
The XAML for the control is here: http://pastebin.com/m35792d4bThe C# is here: http://pastebin.com/m3ecfa90c
Erik
A: 

I agree with Anurag. If you have a button elsewhere on your client that is hosting MyControl you may be able to attach the button event to your control by changing Click="Hello_Click" to Button.Click="Hello_Click". But you would need to have a button further down the logical hierachy so its event could bubble up to your control. The error suggests that MyControl does not subclass Button.

Andrew
The XAML for the control is here: http://pastebin.com/m35792d4bThe C# is here: http://pastebin.com/m3ecfa90c
Erik
Button.Click="Hello_Click" did the trick, Thank you!
Erik