I'm trying to copy every event handlers from one control to another (same type). I found several exemple to do it with Winform but nothing for WPF...
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://ift.tt/o66D3f"
xmlns:x="http://ift.tt/mPTqtT"
xmlns:d="http://ift.tt/pHvyf2"
xmlns:mc="http://ift.tt/pzd6Lm"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<StackPanel x:Name="panel">
<Button x:Name="btn1"
Content="Button 01"/>
</StackPanel>
</Window>
using System;
using System.Windows;
using System.Windows.Controls;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
btn1.Click += (s, e) => Console.WriteLine("Button pressed");
AddButton();
}
private void AddButton()
{
Button btn2 = new Button() { Content = "Button 02" };
panel.Children.Add(btn2);
// Copy all event handler from btn1 to btn2 ??
}
}
}
The thing is that I don't have access to any handlers method name, as i'm suppose to copy the event handlers from another class...
Aucun commentaire:
Enregistrer un commentaire