N.D
N.D

Reputation: 1049

Button click event in custom user control , wpf

I have a custom user control which has some textboxes and some buttons. In my main application (MainWindow.xaml) I use this control like this :

<ScrollViewer Grid.Column="1" 
              VerticalScrollBarVisibility="Auto" 
              HorizontalScrollBarVisibility="Auto" 
              MaxHeight="300" Width="Auto" 
              HorizontalAlignment="Left">
    <StackPanel x:Name="MyStackPanel" 
                Margin="10,0,10,0" 
                MaxHeight="300" Width="Auto">
        <ItemsControl ItemsSource="{Binding}" 
                      x:Name="MyItemsControl" 
                      BorderThickness="0" 
                      Background="Transparent">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <local:MyCustomControl/>
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </StackPanel>
</ScrollViewer>

The DataContext of the ItemsControl is a table from the DataSet. Each textbox in the custom control is binded to some field in the table . I want to implement a click event of some button in the custom control in the MainWindow.xaml.cs , not in the custom control behind code. How can I do it? thanks.

Upvotes: 1

Views: 1024

Answers (1)

Martin Liversage
Martin Liversage

Reputation: 106926

You need to create a new event on the custom control and fire this event in the click event on the button in the code behind of the custom control.

Upvotes: 2

Related Questions