Question

I have a datatemplate for a listbox stored in the ResourceDictionary. The template contains a button which when clicked should pass the listbox item to a seperate listbox

<DataTemplate x:Key="ListBoxContentPresenterTemplate">
        <StackPanel Orientation="Horizontal">
            <StackPanel Height="75" Width="100">
                <TextBlock x:Name="Surname" Text="{Binding Property1}" FontFamily="Arial" FontSize="16" FontWeight="Bold" d:LayoutOverrides="Width"/>
                <TextBlock x:Name="Firstname" Text="{Binding Property2}" Foreground="#FFC9C23E" FontFamily="Arial" FontSize="12" d:LayoutOverrides="Width"/>
            </StackPanel>
            <Button x:Name="Button1" Content="Press" />     
        </StackPanel>
    </DataTemplate>

I don't know how to fire the event as adding it in the xaml as I normally would doesn't work here(presumably as it's a template). Any help would be much appreicated.

Was it helpful?

Solution

DataTemplate is not the problem to subscribe to events. May be only if your DataTemplate is located in a separate resources file, so you have no rational place to place the event handler. If so you can make use of Commands (I believe this will work in version 3 too).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top