c#启动窗口后设置主窗口

时间:2015-08-26 18:51:02

标签: c# wpf mahapps.metro

如果我启动我的应用程序,我会启动一个带有3个按钮的自定义窗口。这是app.xaml代码:

<Application x:Class="EbayManager.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         Startup="ApplicationStart">
</Application>

以下是app.xaml.cs代码:

    private void ApplicationStart(object sender, StartupEventArgs e)
    {
        Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;

        ChooseAccountWindow chooseAccountWindow = new ChooseAccountWindow();
        chooseAccountWindow.ShowDialog();

        MainWindow mainWindow = new MainWindow(chooseAccountWindow.Result);
        mainWindow.Show();
    }

ChooseAccountWindow有3个按钮,这里是CustomAccountWindow.xaml.cs代码:

public partial class ChooseAccountWindow : MetroWindow
{

    public string Result { get; set; }

    public ChooseAccountWindow()
    {
        InitializeComponent();
    }

    private void btnDastaschentuch2013_Click(object sender, RoutedEventArgs e)
    {
        this.Result = "dastaschentuch2013";
        this.Close();
    }

    private void btnSkeptar_de_Click(object sender, RoutedEventArgs e)
    {
        this.Result = "skeptar_de";
        this.Close();
    }

    private void btnAsdf_de_Click(object sender, RoutedEventArgs e)
    {
        this.Result = "asdf_de";
        this.Close();
    }


}

ChooseAccountWindow.xaml应该是第二个窗口,主窗口应该是MainWindow.xaml。按下我想要的按钮后,第二个窗口ChooseAccountWindow.xaml将关闭&amp;应显示主窗口。这是正确的方法吗?因为这两个命令:

MainWindow mainWindow = new MainWindow(chooseAccountWindow.Result);
mainWindow.Show();

打开主窗口,但标题没有显示,我无法设置高度&amp;窗口的宽度。

以下是MainWindow.xaml代码:

<Controls:MetroWindow x:Class="EbayManager.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    Title="MainWindow" Height="3500" Width="525" GlowBrush="{StaticResource AccentColorBrush}">
<Grid>
</Grid>

以下是MainWindow.xaml.cs

的代码
namespace EbayManager
{
public partial class MainWindow : MetroWindow
{
    private string p;

    public MainWindow()
    {
        InitializeComponent();
    }

    public MainWindow(string p)
    {
        // TODO: Complete member initialization
        this.p = p;
        MessageBox.Show(p);
    }
}

}

也许有人可以帮助我。

1 个答案:

答案 0 :(得分:1)

您的评论标题未显示,并且您无法设置窗口的高度和宽度,请告诉我该问题与您在原始帖子中放置的内容无关。问题很可能与MainWindow的WindowStyle或与MainWindow相关的其他属性相关联。