sc 1 year ago
parent
commit
87df99a758
  1. 4
      View/ProgramgroupView.xaml.cs
  2. 14
      Windows/InputBox.xaml
  3. 18
      Windows/InputBox.xaml.cs

4
View/ProgramgroupView.xaml.cs

@ -64,8 +64,8 @@ namespace DyeingComputer.View
private void ProgramgroupView_new_Click(object sender, RoutedEventArgs e)//新建按钮
{
InputBox frm = new InputBox();
frm.Accept += new EventHandler(InputBox_accept);
frm.Show();
frm.Accept += new EventHandler(InputBox_accept);
frm.ShowDialog();
}
void InputBox_accept(object sender, EventArgs e)//新建按钮窗口返回

14
Windows/InputBox.xaml

@ -5,10 +5,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DyeingComputer.Windows"
mc:Ignorable="d"
Title="InputBox" Height="200" Width="400">
<Grid>
<TextBox x:Name="Boxx" HorizontalAlignment="Left" Height="36" Margin="39,31,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="319"/>
<Button Content="Button" HorizontalAlignment="Left" Height="35" Margin="58,104,0,0" VerticalAlignment="Top" Width="96" Click="YES_Click"/>
<Button Content="Button" HorizontalAlignment="Left" Height="35" Margin="158,104,0,0" VerticalAlignment="Top" Width="96" Click="NO_Click"/>
WindowStartupLocation="CenterScreen"
ResizeMode ="NoResize"
Title="SUNLIGHT 838"
Height="150" Width="400">
<Grid FocusManager.FocusedElement="{Binding ElementName=Boxx}">
<TextBox x:Name="Boxx" Height="40" Margin="20,10,20,0" VerticalAlignment="Top" FontSize="26"
MaxLines="1" BorderThickness="3,3,3,3" ClipToBounds="True"/>
<Button Content="YES" HorizontalAlignment="Left" Height="35" Margin="50,70,0,5" VerticalAlignment="Bottom" Width="80" Click="YES_Click"/>
<Button Content="NO" HorizontalAlignment="Right" Height="35" Margin="0,70,50,5" VerticalAlignment="Bottom" Width="80" Click="NO_Click"/>
</Grid>
</Window>

18
Windows/InputBox.xaml.cs

@ -22,6 +22,8 @@ namespace DyeingComputer.Windows
public InputBox()
{
InitializeComponent();
this.DataContext = this;
FocusManager.SetFocusedElement(Boxx, Boxx);
}
public string InputValue
@ -40,16 +42,24 @@ namespace DyeingComputer.Windows
private void YES_Click(object sender, RoutedEventArgs e)
{
if (Accept != null)
var input = Boxx.Text.TrimStart(); //去除字符串前空格
if (input.Length == 0) //字长度不等于0有效
{
Accept(this, EventArgs.Empty);
Boxx.Focus(); //聚焦元素
}
else
{
if (Accept != null)
{
Accept(this, EventArgs.Empty);
}
this.Close(); //关闭窗口
}
this.Close(); //为了测试效果,点击Done以后先不关闭窗口
}
private void NO_Click(object sender, RoutedEventArgs e)
{
this.Close(); //为了测试效果,点击Done以后先不关闭窗口
this.Close(); //关闭窗口
}
}
}

Loading…
Cancel
Save