So, im having an app, where i have to create lots of windows and this windows i use to render in them, so i have to create another window that acts like an overlay. Here is what im doing to set them position
private void ChangeCameras(bool newThread = false)
{
if (newThread)
{
foreach (CameraWindow camera in Window!.OwnedWindows)
{
var dc = camera.DataContext as CellViewModel;
Task.Run(() =>
{
dc!.cameraWindow!.Dispatcher.Invoke(() =>
{
var cell = Cells![$"{dc!.X}:{dc.Y}"];
cell.UpdateLayout();
Point screenPoint = cell.PointToScreen(new Point(0, 0));
camera.Width = cell.ActualWidth - 40;
camera.Height = cell.ActualHeight - 40;
camera.Top = screenPoint.Y + 20;
camera.Left = screenPoint.X + 20;
});
});
}
}
else
{
foreach (CameraWindow camera in Window!.OwnedWindows)
{
var dc = camera.DataContext as CellViewModel;
var cell = Cells![$"{dc!.X}:{dc.Y}"];
cell.UpdateLayout();
Point screenPoint = cell.PointToScreen(new Point(0, 0));
camera.Width = cell.ActualWidth - 40;
camera.Height = cell.ActualHeight - 40;
camera.Top = screenPoint.Y + 20;
camera.Left = screenPoint.X + 20;
}
}
}
im setting them the position of usercontrol element, which named cell
as long as im not creating lots of windows im okay with result, but when there is like 15-20 windows it becomes pretty laggy, so maybe there is some way to optimize it?
how you can see, i`ve already tried to change position of each window in different thread, but it still pretty bad