forum

Home / DeveloperSection / Forums / Can I bind event to a button?

Can I bind event to a button?

Anonymous User 1847 23-Sep-2013

I have collection of such classes:

public class class1

{                 

    public double first {get;set;}

    public double second {get;set;}

    public void divide(object sender, RoutedEventArgs e)

    {

        first/=2;

        second/=2;

    }

}

ObservableCollection<class1> collection1;

That are displayed using wpf and databinding:

<Listbox ItemsSource="{Binding collection1}" >

<ListBox.ItemTemplate>

    <DataTemplate>

        <WrapPanel>

            <TextBox Text="{Binding first}" />

            <TextBox Text="{Binding second}" />

            <Button Content="Divide" />

        </WrapPanel>

    </DataTemplate>

</ListBox.ItemTemplate>

My question is: can I somehow bind each button to it's instance's function divide?


wpf
Updated on 23-Sep-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By