Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you add an Event Trigger to a data template for a business object?
    primarykey
    data
    text
    <p>I have a custom class named BlinkingLight. I also have a static ObservableCollection BlinkingLightCollection. In the UI, I have a ListBox that is bound to BlinkingLightCollection.</p> <p>In my ListBox I want to essentially display each BlinkingLight object as a custom control that looks like box with an LED light that has an animation that makes the LED look like it just flashed on for a second then goes back to normal.</p> <p>My BlinkingLight class has third party "LED" object that raises an event called 'Flash'.</p> <p>I am looking for ideas or solutions to get this to work!</p> <p><strong>My failed attempt:</strong></p> <p>I created a custom control (BlinkingLightControl) that can bind to the data of my BlinkingLight class when a BlinkingLight is the DataContext of my custom control.</p> <p>I created a DataTemplate for my ListBox:</p> <pre><code>&lt;Window.Resources&gt; &lt;DataTemplate x:Key="blinkingLightItemTemplate" &gt; &lt;local:BlinkingLightControl /&gt; &lt;/DataTemplate&gt; &lt;/Window.Resources&gt; &lt;ListBox ItemsSource={Binding Source={x:Static local:Data.BlinkingLightCollection}} ItemTemplate="{StaticResource blinkingLightItemTemplate}" /&gt; </code></pre> <p>Note: I can just put the xaml for my custom control into the datatemplate instead having a completely different control if that makes things easier.</p> <p>Now I want to have an EventTrigger in my BlinkingLightControl (or DataTemplate) who's RoutedEvent is the LED.Flash event. Unfortunately I can't seem to figure this part out. I've tried to create a RoutedEvent in my BlinkingLight class and just raise it whenever I handle the LED.Flash event. However my class is not a UIElement or ContentElement, and per MSDN: <a href="http://msdn.microsoft.com/en-us/library/ms742806.aspx" rel="nofollow noreferrer">MSND Link</a></p> <p>"The routed event owner can be any class, but routed events must be raised by and handled by UIElement or ContentElement derived classes in order to be useful. For more information about custom events, see How to: Create a Custom Routed Event."</p> <p>Any help would be greatly appreciated!! Thanks, Scott</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload