一、下面是简单的WPF窗口案例,图1为主窗体
- 单击显示InputWindow打开窗口输入值点击确认获取文本内容,如果窗口是用ShowDialog打开的,则给DialogResult会自动关闭窗口,并且把DialogREsult属性的值通过ShowDialog方法的返回值返回
- 点击显示ShowYesNo弹出警告框
3.选择图片上传
XAML源码:
<Window x:Class="窗口案例.InputWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="请输入值" Height="150" Width="300" ResizeMode="NoResize"
WindowStartupLocation="CenterScreen">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Name="txtValue" Grid.ColumnSpan="2"></TextBox>
<Button Name="btnOK" Margin="5" Content="确定" Grid.Row="1" Click="btnOK_Click"/>
<Button Name="btnCancel" Margin="5" Content="取消" Grid.Row="1"
Grid.Column="1" Click="btnCancel_Click"/>
</Grid>
</Window>
C#源码
public partial class InputWindow : Window
{
public string InputValue { get; set; }
public InputWindow()
{
InitializeComponent();
}
//public bool IsOK { get; set; }
private void btnOK_Click(object sender, RoutedEventArgs e)
{
InputValue = txtValue.Text;
DialogResult = true;//如果窗口是用ShowDialog打开的,
//则给DialogResult会自动关闭窗口,并且把DialogREsult
//属性的值通过ShowDialog方法的返回值返回
//Close();
//IsOK = true;
}
private void btnCancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
//Close();
//IsOK = false;
}
}