Home > OS >  Cannot share a view into mutiple component
Cannot share a view into mutiple component

Time:07-19

I got a task that need to share camera view from a webcam into 2 Window. I've tried using singleton for create camera view only one time. The problem is that created instance can not share between 2 class. I'm now really confused. What am I doing wrong here?

MainWindow class

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        ReceptionMainWindow receptionMainWindow = new ReceptionMainWindow();
        CustomerMainWindow customerMainWindow = new CustomerMainWindow();
        receptionMainWindow.Show();
        customerMainWindow.Show();

        this.Hide();
    }
}

Receptionist class

    public partial class ReceptionMainWindow : Window
{
    public ReceptionMainWindow()
    {
        InitializeComponent();
        ReceptionWindowHoler.Content = CameraPage.getInstance();
    }
}

Customer Class

    public partial class CustomerMainWindow : Window
{
    public CustomerMainWindow()
    {
        InitializeComponent();
        CustomerWindowHoler.Content = CameraPage.getInstance();
    }
}
        private static CameraPage instance;

Camera class

public CameraPage()
    {
        InitializeComponent();
        //DataContext = CameraViewModel.getInstance();
        this.DataContext = this;
        GetVideoDevices();
    }
    public static CameraPage getInstance()
    {
        if (instance == null)
            instance = new CameraPage();
        return instance;
    }

CodePudding user response:

You could create a Bitmap from the camera view and share it via events to the two other windows.

Take this answer as a workaround. There must be a better way.

  • Related