I wanted to make an application that would download messages from the server and output them to the ListBox.

Before that, I did it on the console application and everything worked.

If I insert a regular line into the list, it is also displayed. But here all together does not want to work. MB, I did something wrong ...

Code:

<Window x:Class="WpfApp1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApp1" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="30"/> <RowDefinition/> </Grid.RowDefinitions> <Grid Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition/> </Grid.ColumnDefinitions> <TextBox x:Name="MsgCount" Margin="1,1,1,1" BorderBrush="Black" Grid.Column="0" FontSize="20"/> <Button x:Name="MsgLoadButton" Margin="1,1,1,1" BorderBrush="Black" Background="White" FontSize="20" Content="Загрузить" Grid.Column="1"/> </Grid> <Grid Grid.Row="1" Margin="1,1,1,1"> <Border BorderBrush="Black" BorderThickness="1,1,1,1"/> <ListBox x:Name="MsgListBox"/> </Grid> </Grid> </Window> 
 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using OpenPop.Pop3; using OpenPop.Mime; using static System.Convert; namespace WpfApp1 { /// <summary> /// Логика взаимодействия для MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); MsgLoadButton.Click += Load_OnClick; } private void Load_OnClick(object sender, EventArgs e) { using (Pop3Client Client = new Pop3Client()) { try { Client.Connect("pop.mail.ru", 995, true); Client.Authenticate("mail@mail.ru", "pass"); int MsgOnServer = Client.GetMessageCount(); int NeedToLoad = ToInt32(MsgCount.Text); List<string> AdressList = new List<string>(); for (int iter = MsgOnServer - NeedToLoad; iter == MsgOnServer; iter++) { AdressList.Add(Client.GetMessage(iter).Headers.From.Address); } MsgListBox.ItemsSource = AdressList; } catch (Exception exc) { MsgCount.Text = exc.Message; } } } } } 
  • one
    Have you tried to trace? Is the code branch running? - VladD
  • You have an invalid and very strange for loop. Most likely, it is never executed, so the AdressList remains empty. - Nikita

0