我做了这个语句来检查TextBox是否为空,但MessageBox总是显示TextBox是否为空.
private void NextButton_Click(object sender, EventArgs e)
{
decimal MarkPoints, x, y;
x = HoursNumericUpDown.Value;
y = MarkNumericUpDown.Value;
MarkPoints = x * y;
//decimal MarkPoints = (decimal)HoursNumericUpDown.Value * (decimal)HoursNumericUpDown.Value;
DataGridViewRow dgvRow = new DataGridViewRow();
DataGridViewTextBoxCell dgvCell = new DataGridViewTextBoxCell();
dgvCell = new DataGridViewTextBoxCell();
dgvCell.Value = MaterialTextBox.Text;
dgvRow.Cells.Add(dgvCell);
dgvCell = new DataGridViewTextBoxCell();
dgvCell.Value = HoursNumericUpDown.Value;
dgvRow.Cells.Add(dgvCell);
dgvCell = new DataGridViewTextBoxCell();
dgvCell.Value = MarkNumericUpDown.Value;
dgvRow.Cells.Add(dgvCell);
dgvCell = new DataGridViewTextBoxCell();
dgvCell.Value = MarkPoints;
dgvRow.Cells.Add(dgvCell);
dataGridView1.Rows.Add(dgvRow);
MaterialTextBox.Clear();
HoursNumericUpDown.Value = HoursNumericUpDown.Minimum;
MarkNumericUpDown.Value = MarkNumericUpDown.Minimum;
if …Run Code Online (Sandbox Code Playgroud) 有问题的文本框涉及我的代码中的if语句,这是有效的
if (textbox.text != "")
{
do this
}
Run Code Online (Sandbox Code Playgroud)
我很好奇,如果一个空文本框将被视为空字符串或空语句.
我无法理解IsEmpty这段代码(Path=Text.IsEmpty)(来自水印TextBox)的来源:
<Grid Grid.Row="0" Background="{StaticResource brushWatermarkBackground}"
Style="{StaticResource EntryFieldStyle}" >
<TextBlock Margin="5,2" Text="Type to search ..." Foreground="Gray"
Visibility="{Binding ElementName=entry, Path=Text.IsEmpty,
Converter={StaticResource BooleanToVisibilityConverter}}"/>
<TextBox Name="entry" Background="Transparent"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
你可以看到一个字符串没有任何IsEmpty属性.A DependencyProperty也没有任何IsEmpty成员.我甚至尝试在IsEmpty对象浏览器窗口中搜索,但没有任何相关结果解释代码.
你能解释一下IsEmpty这里的参考吗?(关于它的任何参考链接都很棒).
谢谢!
在WPF TextBox中,我想提供在第一次输入后消失的描述.这应该为用户提供一些帮助,他应该在文本字段中输入什么.
可以使用Label在给定的TextBox上方显示文本.我对一个例子感兴趣,但找不到任何例子.理想情况下,解决方案仅适用于XAML.