gpt4 book ai didi

c# - WPF在不同窗口中镜像网格内容

转载 作者:太空宇宙 更新时间:2023-11-03 10:35:29 25 4
gpt4 key购买 nike

我正在开发 WPF 软件。在主窗口中,我有一个名为“gridWindow”的网格和一些按钮。每个按钮点击事件实际上会分别调出不同的窗口,然后抓取窗口中的内容添加到主窗口的网格中。

private void btnWelcome_Click(object sender, RoutedEventArgs e)
{
Window_Welcome childWindow = new Window_Welcome();
object PrjWindowContent = childWindow.Content;
childWindow.Content = null;
gridWindow.Children.Add(childWindow as UIElement);
}

然后我有另一个按钮需要打开一个名为“BlackScreen”的新窗口并镜像主窗口网格中的所有内容。MainWindow 中网格内的内容始终根据系统时间或来自其他 MainWindow 控件的用户输入而变化。镜像窗口的内容也需要相应地改变。

我了解到我可能需要一个视觉画笔来复制屏幕。但我就是没有这样做。

这是我在 BlackScreen.xaml 中的代码。

<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>

<Grid Grid.Row="0" Background="Black">
<Viewbox Name="vbox" Stretch="Uniform"><!--DataContext="{Binding ElementName=gridWindow}"-->
<Grid>
<Grid.Background>
<VisualBrush Stretch="Uniform" Visual="{Binding}">
</VisualBrush>
</Grid.Background>
</Grid>
</Viewbox>
</Grid>
</Grid>

最佳答案

这是一个简单的示例,说明如何使用 VisualBrush 来“镜像”您的主要内容 Grid(或您的 UI 的任何其他部分):

<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid Name="MainContent">
<Ellipse Fill="Red" />
<Rectangle Fill="Yellow" Margin="50" />
</Grid>
<Rectangle Grid.Row="1">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=MainContent}" />
</Rectangle.Fill>
</Rectangle>
</Grid>

这会产生以下内容:

enter image description here

关于c# - WPF在不同窗口中镜像网格内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27978239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com