朋友们!有一个主窗口,它包含一个框架,我用它在页面之间切换。我有一个有画布的页面。后台流中的画布以马赛克视图中的图像形式接收数据。
foreach (var item in CoreData.fillWallArray.GetConsumingEnumerable())
{
if (File.Exists(item.PathFile))
{
Application.Current.Dispatcher.Invoke(new Action(() =>
{
Image image = new Image();
image.Source = BitmapImageFromFile(item.PathFile);
image.Width = (int)Math.Truncate((CoreData.settings.CellWidth * 30) / 2.54);
image.Height = (int)Math.Truncate((CoreData.settings.CellHeight * 30) / 2.54);
Canvas.SetLeft(image, item.Column * (int)Math.Truncate((CoreData.settings.CellWidth * 30) / 2.54));
Canvas.SetTop(image, item.Row * (int)Math.Truncate((CoreData.settings.CellHeight * 30) / 2.54));
can.Children.Add(image);
}));
Thread.Sleep(100);
}
}
我的任务是将这个画布带到第二个屏幕。为此,我创建了第二个窗口,并作为上下文传递了我需要的画布。
var _BroadcastWindow = new BroadcastWindow();
_BroadcastWindow.DataContext = this.can;
_BroadcastWindow.Show();
在第二个窗口中,我链接了数据。
<Grid>
<Grid.Background>
<VisualBrush Visual="{Binding}"/>
</Grid.Background>
</Grid>
一切正常,画布中的数据同步显示在第二个窗口中。但是一旦我切换到另一个页面,Visualbrush 就不再更新了。一旦我切换回带有我在第二个窗口中看到的画布的页面,它就会更新。可能是什么问题呢?在后台线程中向画布添加数据时,我也尝试调用 Measure、Arrange、UpdateLayout,但这并没有产生结果。