2010-05-14 44 views

回答

1

这是一个方式组织代码:

second.xaml应该包含你的窗口definiton如:

<Window x:Class="MediaCheckerWPF.AboutBox" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="About Media Checker" Height="300" Width="400" ResizeMode="NoResize" 
    Icon="/MediaCheckerWPF;component/Resources/checker.ico" 
    ShowInTaskbar="False"> 
    <Grid> 
     ... 
    </Grid> 
</Window> 

first.xaml有按钮,例如:

<Button Height="23" HorizontalAlignment="Right" Name="aboutButton" 
VerticalAlignment="Top" Width="23" Click="AboutButton_Click" 
Content="{DynamicResource TInformationButton}" 
ToolTip="{DynamicResource TInformationButtonTooltip}" Margin="0,0,8,0"/> 

然后在后面的代码:

private void AboutButton_Click(object sender, RoutedEventArgs e) 
{ 
    var about = new AboutBox { Owner = this }; 
    about.Initialise(); 
    about.Show(); 
} 
0

ChrisF的回答是在Windows风格的应用程序中弹出一个新窗口的好方法,除非您不应该以这种方式调用Initialize(它应该从构造函数中调用)。

如果您想改为使用网页式导航,则应使用Page类而不是Window以及NavigationService。这也允许您的WPF应用程序在真实的Web浏览器中运行。

相关问题