I have 3 stack panels
which are holding label and textbox
contained in one big stack panel, so it looks like this:
<StackPanel Name="stackControls" Grid.Row="1" Orientation="Vertical" VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Center">
<Label x:Name="lblName" Content="Broj kase:" Foreground="Black" FontSize="14" VerticalAlignment="Center"/>
<TextBox Name="txtName" VerticalContentAlignment="Center" FontSize="15" Foreground="Black" FontFamily="Arial" Style="{StaticResource TextBoxStyle1}" Width="500" Height="45" />
</StackPanel>
<StackPanel HorizontalAlignment="Right" Margin="0,5,0,0" Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Center">
<Label x:Name="lblLastName" Content="Generični printer:" Foreground="Black" FontSize="14" VerticalAlignment="Center"/>
<TextBox Name="txtLastName" VerticalContentAlignment="Center" FontSize="15" FontFamily="Arial" Width="500" Style="{StaticResource TextBoxStyle1}" Height="45" />
</StackPanel>
<StackPanel HorizontalAlignment="Right" Margin="0,5,0,0" Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Center">
<Label x:Name="lblHeader" Content="Veličina naslova na gridu:" Foreground="Black" FontSize="14" VerticalAlignment="Center"/>
<TextBox Name="txtHeader" VerticalContentAlignment="Center" FontSize="15" FontFamily="Arial" Width="500" Style="{StaticResource TextBoxStyle1}" Height="45" />
</StackPanel>
</StackPanel>
I must deny user on edit of any of this fields txtName, txtLastName, or txtHeader to leave blank field, so I wanted to loop through each stackpanel and through each textbox to check is text empty, if yes I would return and throw him a popup with message like : some of fields are empty, it would be awesome if I could specify which fields exactly, maybe I could use tags for that..?
This is what I've tried so far:
foreach (var c in this.stackControls.Children)
{
if (c is StackPanel)
{
TextBox textBox = c as TextBox;
if (String.IsNullOrEmpty(textBox.Text))
{
MessageBox.Show("Some fields are empty.",
"Edit",
MessageBoxButton.OK,
MessageBoxImage.Information);
return;
}
}
}
But with this code above I would always loop only through containers ( those 3 stack panels) and I couldn't each up textboxes...
Thanks guys Cheers