MainWindow.xaml:
<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>
<Button Click="Button_Click" Grid.Row="2" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalAlignment="Bottom" VerticalContentAlignment="Center" Content="Click"/>
</Grid>
</Window>
MainWindow.xaml.cs:
private void Button_Click(object sender, RoutedEventArgs e)
{
Window1 window = new Window1();
window.Show();
}
Window1.xaml:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<Canvas />
</Grid>
</Window>
爲什麼你想顯示'MessageBox'? mainCanvas是一個畫布控件嗎? – Abhishek
沒有消息框只是我想要做的彈出類型的一個例子,我只是想讓它打開一個新窗口並顯示我的畫布。 –