I'm developing a WPF and C# application and i have problems to pass data between a page and a window.
How is the best way to do it?
Thanks!
I'm developing a WPF and C# application and i have problems to pass data between a page and a window.
How is the best way to do it?
Thanks!
You can use a delegate
event to do this.
For example in your MainWindow :
namespace WpfApplication1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Page1.onNameSend += Page1_onNameSend;
}
void Page1_onNameSend(string Name)
{
Console.WriteLine(Name);
}
}
}
And then in your 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");
}
}
}
Hope that helps.
I recently had this issue and was able to solve with public application properties. i do not know if this is the "best practice" in fact I doubt it but it can solve the issue.
//creating a new property
Application.Current.Properties["accessName"] = newPropertyValue;
//retrieving
RecievingWindowVariable = (castDataType)Application.Current.Properties["accessName"];