Reputation: 201
I am developing a WPF softare. At a Main Window, I have a grid named "gridWindow" and a few buttons. Each button click event will actually calls up different windows respectively and then grab the content in the window and add into the grid in Main Window.
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);
}
Then I have another button which will need to open a new window named "BlackScreen" and mirror everything in the Main Window's grid. The content inside the grid in MainWindow is always changing based on the system time or user input from others MainWindow's controls. The mirroring window's content will need to change accordingly too.
I learnt that I might need a visual brush to duplicate the screen. But I just failed to do so.
This is my code in the 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>
Upvotes: 3
Views: 1589
Reputation: 69979
Here is a simple example of how you could use the VisualBrush
to 'mirror' your main content Grid
(or any other section of your 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>
This produces the following:
Upvotes: 3