Note that there are some explanatory texts on larger screens.

plurals
  1. POforeach statement cannot operate on variables of type System.Windows.Controls.Textbox
    primarykey
    data
    text
    <p>This is the error I'm getting - 'foreach statement cannot operate on variables of type System.Windows.Controls.Textbox because System.Windows.Controls.Textbox does not contain a public definition for GetEnumerator.'</p> <p>My code:</p> <pre><code>private void btnSendEmail_Click_1(object sender, RoutedEventArgs e) { MailMessage message = new MailMessage(); message.From = new MailAddress(txtEmail.Text); message.Subject = txtSubject.Text; message.Body = txtBody.Text; foreach (string s in txtEmailAddresses) { message.To.Add(s); } SmtpClient client = new SmtpClient(); client.Credentials = new NetworkCredential(); } </code></pre> <p>There's a red squiggly underline on 'foreach' with that error. The textbox is supposed to be a multi-line textbox. With winForms this is easy. I could just go to the properties window and set the multi-line property to true, then it works fine, as long as the addresses the user enters are separated by a semi-colon. However, everything that takes 2 seconds in winforms needs to be a big problem in WPF, so I'm getting that error with the WPF textbox. Does anyone know why I'm getting that error and what to do about it? Here's my xaml too in case there's some property I'm missing that needs to be set on the textbox to make it multi-line or something. </p> <pre><code>&lt;Label Content="Recipients:" HorizontalAlignment="Left" Margin="26,10,0,0" VerticalAlignment="Top" /&gt; &lt;Label Content="Subject:" HorizontalAlignment="Left" Margin="26,114,0,0" VerticalAlignment="Top" /&gt; &lt;TextBox x:Name="txtEmailAddresses" HorizontalAlignment="Left" Height="73" Margin="26,36,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="278" ToolTip="When providing multiple email addresses, separate them with a semi colon" /&gt; &lt;TextBox x:Name="txtSubject" HorizontalAlignment="Left" Height="23" Margin="81,117,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="223" /&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload