I have following XAML in WPF
<Canvas>
<WrapPanel x:Name="TimeTableMainWrapPanel" Canvas.Left="109" Canvas.Top="195" Height="601" Width="745>
<TextBox x:Name="txtFirstLctrTime" Height="24" TextWrapping="Wrap" Width="115"/>
<TextBox x:Name="txtSecondLctrTime" Height="23" Canvas.Left="594" TextWrapping="Wrap" Canvas.Top="189" Width="115"/>
<WrapPanel x:Name="TimeTableSubWrapPanel" Canvas.Left="109" Canvas.Top="195" Height="601" Width="745">
<WrapPanel x:Name="FirstLecture" Background="#00F0F8FF" Height="392" Width="133" Margin="0,0,10,0">
<TextBox x:Name="txtMondayFirstLctr" Width="133" Margin="0" Height="30" FontSize="13" VerticalContentAlignment="Center"/>
<TextBox x:Name="txtTuesdayFirstLctr" Width="133" Margin="0,38,0,0" Height="30" FontSize="13" VerticalContentAlignment="Center"/>
</WrapPanel>
<WrapPanel x:Name="SecondLecture" Canvas.Top="220" Background="#00F0F8FF" Canvas.Left="270" Height="466" Width="133" Margin="8,0,10,0">
<TextBox x:Name="txtMondaySecondLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
<TextBox x:Name="txtTuesdaySecondLctr" Width="133" Margin="0,38,0,0" Height="30" VerticalContentAlignment="Center"></TextBox>
</WrapPanel>
</WrapPanel>
</WrapPanel>
</Canvas>
I wanted to clear content of all textbox on button click. And for that I am doing
var firsttextboxes = this.FirstLecture.Children.OfType<TextBox>();
var secondtextboxes = this.SecondLecture.Children.OfType<TextBox>();
foreach (var textbox in firsttextboxes)
{
textbox.Clear();
}
foreach (var textbox in secondtextboxes)
{
textbox.Clear();
}
Is there any better way of doing this, instead of using multiple foreach
loops?
Also how do I enter one value in each TextBox
and move to next?
I am trying the code below, but it is inserting the same value in all TextBox
objects:
foreach(var a in firsttextboxes )
{
foreach(var b in Text)
{
a.Text = b
}
}