最近项目中用到window镶嵌window功能,但是网上没有相关的资料,甚至很多人说没办法在window镶嵌window,后来我想到一个变通的方法,如下:
前台source:
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Frame Height="150" HorizontalAlignment="Left" Margin="85,30,0,0" Name="frame1" VerticalAlignment="Top" Width="340" /> <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="111,249,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" /> </Grid> </Window>
后天source:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void button1_Click(object sender, RoutedEventArgs e) { Window1 win = new Window1(); this.frame1.Content = win.Content; } }
虽然可以实现镶嵌window,但是只是获取window中的所有,放到Frame中,
期待牛人有更好用的方法。