Events in DataTemplates
Posted: 30 Apr 2015, 04:05
I have a tough issue that I cant figure out how to solve in Unity.
I have an Items Control inside a data template. This is the simplified form
They are displayed in a content presenter based on the Story node you are on, there are various nodes for different story GUI (Dialog Statements, Narration Views with Images etc.)
Now I need to change a property on the ViewModel when the user mouse overs the button. This is a dialog selection and I swap portraits based on the dialog you mouse over. (the options might be good evil etc. so I swap the portrait of the player)
I cannot attach to the button events in the code behind monobehavior as the buttons are created adhoc when I add responses to the items source. How can I respond to the MouseEnter event of these buttons?
I have an Items Control inside a data template. This is the simplified form
Code: Select all
<DataTemplate DataType="{x:Type nodes:StatementNode}">
<ItemsControl ItemsSource="{Binding DataContext.Responses, ElementName=StoryRoot}"
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding Text}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
Code: Select all
<ContentPresenter Content="{Binding CurrentNode}">
</ContentPresenter>
I cannot attach to the button events in the code behind monobehavior as the buttons are created adhoc when I add responses to the items source. How can I respond to the MouseEnter event of these buttons?