Users Pricing

forum

Home Forums Can I bind event to a button? – MindStick

Can I bind event to a button?

Anonymous User 2192 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?


1 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md