I am developing a wpf application using Prism that:
opens the application on monitor 1. Should launch a full screen window on monitor 2.
This window will be used to draw graphics.
How do I create 2 windows using Prism? Should I show this using a dialog or is there a better way a window on second monitor and draw grpahics?
You have to use System.Windows.Forms to use "Screen" which will provide you connected screens/monitors with resolution, Primary Display and other info.
You have to create another Window/Shell for secondary display along with a separate region manager to manage secondary display's region and navigation.. Refer below method for creation of secondary window and region manager
InitializeShell(Window shell) method
Now You also have to create a separate Region Manager and store the instance in some global kind of variable to manage navigation on secondary display.
protected override void InitializeShell(Window shell)
base.InitializeShell(shell);
Current.MainWindow.Show();
var regionManager = this.Container.Resolve<IRegionManager>();
var secondRegionManager = regionManager.CreateRegionManager();
SecondaryWindow secondaryWindow = new SecondaryWindow(secondRegionManager);
System.Drawing.Rectangle rectangle = secondaryScreen.WorkingArea;
secondaryWindow.WindowState = System.Windows.WindowState.Normal;
secondaryWindow.WindowStartupLocation =
System.Windows.WindowStartupLocation.Manual;
secondaryWindow.Top = rectangle.Top;
secondaryWindow.Left = rectangle.Left;
secondaryWindow.Show();
secondaryWindow.WindowState = System.Windows.WindowState.Maximized;
GlobalVariables.SecondaryRegionManager = secondRegionManager; // storing in global variable
Related
I try to create WPF application (.net Core 3.1) with support touch screen and non-touch screen with two inputs at the same time.
I found a sample how to do this with VWvare and Virtual maschine here is the sample,
but I want to do something easier and without install 3rd party software.
I want to do something similar to the situation in the bank. The employee is working on the computer and the customer is "playing" with the app on the touch screen.
I have created two application parts (two separate Windows), 1. for main screen and 2. for touch screen.
The problem occurs when a customer clicks on their screen, so he takes the focus from the employee's screen.
I think this is a window setup rather than an application. I created Virtual Desktop, but it does not work separately input on touch screen. It always steals focus from the main screen.
Please how to make an two independent inputs into the application window?
Create new instance of your window and than assign DataContext from original window
var viewModel = _container.Resolve<IViewModel>()
Window win1 = new Window();
win1.DataContext=viewModel;
win1.Show();
//move window to 1st screen
Window win2 = new Window();
win2.DataContext=win1.DataContext;
win2.Show();
//move window to 2nd screen
I change the color of the form at run time from a color pallet.
How can I apply this color to all other forms of my application
within one namespace?
What if the forms are in different namespaces?
creating unnecessary static variables in your application may cause lots of performance and memmory issues. Below will be a good solution to your needs.
Store a color as settings value on your application starts
Properties.Settings.Default.FormBackGroundColor = Color.Red; //your color here
In all other window initialize use below line
this.BackColor = Properties.Settings.Default.FormBackGroundColor;
With WPF, want to open a second window full screen. The problem is when the main window is not in the primary screen, the second window doesn't open in the same screen like the main window. It popups inside the primary screen. Is there anyway I can get it open inside the same screen like the main window? Thanks.
You should be able to do this by setting the startup location for the new window to center on its owner. The gotcha to doing that is that you don't get the window it's opened from set as the owner automatically so you need to do it yourself. Doing this from another Window should open the Window2 instance full screen on the same monitor:
Window2 newWindow = new Window2
{
Owner = this,
WindowStartupLocation = WindowStartupLocation.CenterOwner,
WindowState = WindowState.Maximized
};
newWindow.Show();
given window is the instance of the window you want to center
var window = new MyWpfWindow();
var handle = Process.GetCurrentProcess().MainWindowHandle;
var helper = new WindowInteropHelper(window);
helper.Owner = handle;
window.WindowState = WindowState.Maximized;
window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
window.ShowDialog();
this will automatically retrieve the current main window and centers and maximize the child in the same screen, it works for me in an Excel VSTO add-ins
I have lots of windows in my project. Now I am thinking to convert it into pages then then implement it into frame navigation.
Is there any way to convert all the windows into frames?
There's a very simple way : build a new page then set the page content = the window content. But you loose some properties (width, height) some events loader (Loaded,...), and obviously some operations are not allowed on pages.
If you want to try without taking too much risk on your project, take a few windows (W1,W2,W3), then create the pages P1,P2,P3. Now create W1', W2', W3', which are just a Window with a frame linked to P1, P2, P3 respectively. This way you can check if your app can be 'translated' to page logic and begin testing navigation while still having full functionnalities for the Windowed version of your application. Note that if your application follows MVVM, the translation 'should' be easy.
I use two displays with different resolutions on my development machine. The display with a smaller resolution is configured as primary display. If I maximize my WPF application on the secondary display and show a popup control at the bottom it appears repositioned:
I guess, the framework uses the lower resolution of the primary display to check if the popup window has to be repositioned. Doesn't the WPF framework check for the current display resolution or do I have to configure this myself?
For repositioning popup control on two monitor, better to set Popup control Horizontal and Vertical offset based on PointToScreen property of MainWindow
var mousePosition = Mouse.GetPosition(Application.Current.MainWindow);
var pointToScreen = Application.Current.MainWindow.PointToScreen(mousePosition);
_popup.HorizontalOffset = pointToScreen.X;
_popup.VerticalOffset = pointToScreen.Y;