Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - Handling events in control templates

 
 
Old 08-04-2006   #1 (permalink)
Illumineo


 
 

Handling events in control templates

Take a custom control and put in the generic.xaml template an image,
something like;

<Style TargetType="{x:Type local:ClassShape}" >
....
<Image Source="collapse.gif" Canvas.Left="88" Canvas.Top="10"
Name="collapseImage" Cursor="Hand" MouseDown="Go">

and the CLR complains that

The root element <ResourceDictionary> requires a x:Class attribute in
order to support event handlers in the XAML file. Either remove the
event handler for the MouseDown event, or add a x:Class attribute to
the root element.

Now, if I add the x:Class="ClassShape", as required, I get the error
that the 'Go' handler cannot be found. The reason is that the generated
generic.xaml.cs creates a ClassShape class which inherits from the
ResourceDictionary base class and which has no link to my actual
ClassShape class (that is, the custom control).

This is weird and I have not found any solution anywhere on the net.
Nobody is putting event handlers in custom control templates? Is the
communication between a template and the underlying class supposed to
be only in one direction? I have also tried to fetch the template's
controls via the VisualTreeHelper but the Template property remains
'null' whatever I try.

In any case, I don't think what I try to achieve is exotic, so it's
even more frustrating....

Thanks a lot for any hint or direction!


My System SpecsSystem Spec
Old 08-07-2006   #2 (permalink)
Illumineo


 
 

Re: Handling events in control templates

Nobody seems to have an answer but I think I found a solution myself...
Seemingly it is not possible to wire an event handler in a custom
control, it's much more complicated; very confusing in fact. The answer
resides in the NumericUpDown sample of the SDK wherein you can see that
you need a lot of code and custom commands to route a user action to an
underlying control handler.

Hope this will help someone, somewhere, some day.

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
PPT converted to HTM - handling WMP events... .NET General
Handling Events in a VBScript Class VB Script
Handling .NET events? PowerShell
Handling events from COM? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46