如果我启动我的应用程序,我会启动一个带有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);
}
}
}
也许有人可以帮助我。
答案 0 :(得分:1)
您的评论标题未显示,并且您无法设置窗口的高度和宽度,请告诉我该问题与您在原始帖子中放置的内容无关。问题很可能与MainWindow的WindowStyle或与MainWindow相关的其他属性相关联。