开发者

Silverlight 3 Datatemplate: Firing a button_click event

开发者 https://www.devze.com 2023-01-28 05:36 出处:网络
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

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:Na开发者_运维技巧me="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.


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消