how to change the layout of a control inside a parent wpf form from a child winform?

i have two separate projects inside a solution, one is a wpf the other is windows form and i have referenced the winform to the wpf project.. Inside the wpf window is an image control, when clicked, a windows form with a button would appear.

How i can be able to change the image source of the image control inside the wpf form when the button inside the winform is clicked...

i have seen a similar question to this but i cant understand the answers...

Answers


You could pass a delegate/Action into the Winform to perform the action

Here is a very quick example

WPF

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
    }

    private void Button_Click_1(object sender, RoutedEventArgs e)
    {
       // pass in the method you want to call when the winform button is clicked
       var winform = new Form1(() => ChangeImage()).ShowDialog();
    }

    private void ChangeImage()
    {
        // your change image logic
    }
}

Winforms

public partial class Form1 : Form
{
    private Action _action;

    public Form1()
    {
        InitializeComponent();
    }

    public Form1(Action action)
    {
        _action = action;
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (_action != null)
        {
            // call the method in the WPF form
            _action.Invoke();
        }
    }
}

Need Your Help

How can I specifiy what access I need from my user's Facebook accounts when using OmniAuth?

ruby-on-rails facebook facebook-graph-api omniauth

When you use OmniAuth to login to a web app through Facebook, these are the permissions the webapp has:

Typedef for pointer to a template class method

c++ templates c++11 typedef

The title sums my question up - I need a generic typedef for a pointer to a template class method, as explained in the code below. The typedef needs to be generic.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.