私は WPF と C# アプリケーションを開発していますが、ページとウィンドウの間でデータを渡すのに問題があります。
どのように行うのが最善の方法ですか?
ありがとう!
delegate
これを行うには、イベントを使用できます。たとえば、あなたの MainWindow で:
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Page1.onNameSend += Page1_onNameSend;
}
void Page1_onNameSend(string Name)
{
Console.WriteLine(Name);
}
}
}
そして、あなたの Page1 で:
namespace WpfApplication1
{
public partial class Page1 : Page
{
public delegate void SendName(string Name);
public static event SendName onNameSend;
public Page1()
{
InitializeComponent();
}
private void SendButton(object sender, RoutedEventArgs e)
{
onNameSend("Name to Send");
}
}
}
それが役立つことを願っています。