void StartRequest(IAsyncResult res) { try { client.EndConnect(res); var stream = client.GetStream(); string message; message = "получитьвопросы:" + ID.ToString(); message = HttpUtility.UrlEncode(message, Encoding.UTF8); byte[] data = Encoding.Unicode.GetBytes(message); stream.Write(data, 0, data.Length); { data = new byte[64]; // буфер для получаемых данных StringBuilder builder = new StringBuilder(); int bytes = 0; do { bytes = stream.Read(data, 0, data.Length); builder.Append(Encoding.UTF8.GetString(data, 0, bytes)); }while (stream.DataAvailable); message = HttpUtility.UrlDecode(builder.ToString(), Encoding.UTF8); var arr = message.Split('/'); try { foreach (var item in arr) { var one = new Quetion(item); Dispatcher.Invoke((() => { QuetionPage two = new QuetionPage(one); Quetions.Items.Add(two); })); } } catch { } stream.Close(); client.Close(); } } catch { this.Dispatcher.Invoke(() => { ConnectButton.IsEnabled = true; State.Content = "Не удалось подключится к серверу"; }); client.Close(); } }
public QuetionPage(Quetion q) : base() { Visibility = Visibility.Collapsed; quetionBlock = new TextBlock(); answers = new List <FrameworkElement>(); this.quetion = q; Panel = new StackPanel(); this.Content = Panel; setQuetion(quetion.quetion); setAnswers(quetion.answers); Panel.Children.Add(quetionBlock); foreach (var item in answers) { Panel.Children.Add(item); } }