![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| 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 | |||