0

Microsoft Expression Blend 4 でベアボーン WPF プロジェクトを作成しました。

次に、Visual Studio 2012 でプロジェクトを開き、単純なクラスをプロジェクトに追加しました。

このクラスをスタートアップ オブジェクトとして使用するようにアプリケーション プロパティを設定します。

新しいメインウィンドウを作成し、オブジェクトに対して show 関数を使用しました。

ウィンドウが 1 ミリ秒間ポップアップしてから閉じます。

MainWindow を呼び出して開いたままにするにはどうすればよいですか?

Class1.cs

//This is the Class I created
using System;
using System.Collections.Generic;

namespace WpfApplication5
{
    static class Class1
    {
        [STAThread]
        static void Main()
        {
            MainWindow winMain = new MainWindow();
            winMain.Show();
        }

    }
}

MainWindow.xaml.cs

//This is the Mainwindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApplication5
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();

        }
    }
}

MainWindow.xaml

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication5.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">

    <Grid x:Name="LayoutRoot"/>
</Window>

App.xaml

<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="WpfApplication5.App"
    StartupUri="MainWindow.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>

App.xaml.cs

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Windows;

namespace WpfApplication5
{
public partial class App : Application
    {
    }
}
4

1 に答える 1

1

アプリケーションに 2 つのエントリ ポイントを設定します。1 つは App.xaml にあり、もう 1 つは Class1.cs にあります。Class1.cs から以下のコード ブロックを削除することをお勧めします。

[STAThread] 
static void Main() 
{
  MainWindow winMain = new MainWindow();
  winMain.Show();
}
于 2013-07-15T05:29:25.147 に答える