8,757
社区成员
发帖
与我相关
我的任务
分享//Window1.cs
using System;
using System.Windows;
using System.Windows.Controls; // Button et al
namespace MyFirstWpfApp {
class Window1 : Window {
public Window1() {
this.Text = "Hello, Wpf";
// Do something interesting
Button button = new Button();
button.Content = "Click me, baby, one more time!";
button.Width = 200;
button.Height = 25;
button.Click += button_Click;
this.AddChild(button);
}
void button_Click(object sender, RoutedEventArgs e) {
MessageBox.Show("You've done that before, haven't you...", "Nice!");
}
}
}
//MyApp.cs
using System;
using System.Windows;
namespace MyFirstWpfApp {
class MyApp : Application {
[STAThread]
static void Main(string[] args) {
MyApp app = new MyApp();
app.StartingUp += app.AppStartingUp;
app.Run(args);
}
void AppStartingUp(object sender, StartingUpCancelEventArgs e) {
// Let the Window1 initialize itself
Window window = new Window1();
window.Show();
}
}
}
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutputType>winexe</OutputType>
<OutputPath>.\</OutputPath>
<Assembly>1st.exe</Assembly>
</PropertyGroup>
<ItemGroup>
<Compile Include="MyApp.cs" />
<Compile Include="Window1.cs" />
<Reference Include="System" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<Import Project="$(MsbuildBinPath)\Microsoft.CSharp.targets" />
</Project>
private void Application_Startup(object sender, StartupEventArgs e)
{
// 代码在这里
}
protected override void OnStartup(StartupEventArgs e)
{
}
protected override void OnExit(ExitEventArgs e)
{
}