1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
| public class LoginWindowPure : Window
{
private TextBox userNameBox;
private PasswordBox passwordBox;
public LoginWindowPure()
{
Title = "Login";
Width = 320; Height = 200;
WindowStartupLocation = WindowStartupLocation.CenterScreen;
var grid = new Grid { Margin = new Thickness(16) };
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
var userLabel = new TextBlock { Text = "用户名", Margin = new Thickness(0, 0, 0, 4) };
Grid.SetRow(userLabel, 0);
grid.Children.Add(userLabel);
userNameBox = new TextBox { Height = 28 };
Grid.SetRow(userNameBox, 1);
grid.Children.Add(userNameBox);
var pwdLabel = new TextBlock { Text = "密码", Margin = new Thickness(0, 12, 0, 4) };
Grid.SetRow(pwdLabel, 2);
grid.Children.Add(pwdLabel);
passwordBox = new PasswordBox { Height = 28 };
Grid.SetRow(passwordBox, 3);
grid.Children.Add(passwordBox);
var buttonPanel = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Right,
Margin = new Thickness(0, 16, 0, 0)
};
Grid.SetRow(buttonPanel, 4);
var cancelButton = new Button { Content = "取消", Width = 80, Margin = new Thickness(0, 0, 8, 0), IsCancel = true };
var loginButton = new Button { Content = "登录", Width = 80, IsDefault = true };
loginButton.Click += LoginButton_Click;
buttonPanel.Children.Add(cancelButton);
buttonPanel.Children.Add(loginButton);
grid.Children.Add(buttonPanel);
Content = grid;
}
private void LoginButton_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show($"Login: {userNameBox.Text}");
}
}
|