2010-05-14 71 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瀏覽器中運行。

相關問題