Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data between WPF Windows

Tags:

c#

forms

wpf

So I have been looking around and haven't found a solution for this, using WPF Windows.

So what I want to do is to send values from two sliders from one WPF Window to another. How should this be done using two WPF Windows inside the same project? And is it possible to do it from another project inside the same solution using references?

I have been working with Windows forms and can get it to work easily there, but it just won't work with WPF Windows.

[Edited] What needs to be done is very basic really. We have a menu Project called Startup with a MainWindow.xaml that does not yet contain any code that needs to be mentioned. Although, we want from the menu, to be able to use 2 sliders, 1 to set the amount of players that are going to participate and another to set the amount of hours that the game should last. We have fixed this problem already from the game itself by setting the amount of players like this:

private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)  // Change move-army-strenght
{
    movearmy = Convert.ToInt32(slider1.Value);
    lblresult3.Content = "" + movearmy;
    if (menuphase == 1) { players = Convert.ToInt32(slider1.Value); }
}

This will check if it's menuphase one and then get the amount of players from that. Although, we want to send this value from the Menu, not while inside the game!

like image 473
JakobMiller Avatar asked Jul 24 '26 12:07

JakobMiller


1 Answers

It may well be overkill for your requirements, but an extensible way to send messages with data between forms, windows, etc. is to use the Mediator Design Pattern. There is an excellent article and sample project by Marlon Grech for a WPF Mediator.

This pattern works well for sending a variety of messages, so long as there aren't too many subscribers looking for the messages.

like image 88
Dave Clemmer Avatar answered Jul 26 '26 00:07

Dave Clemmer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!