Xamarin.Forms UWP应用Xamarin编辑器查看显示内容

时间:2019-02-04 19:11:51

标签: xamarin xamarin.forms uwp

我在Xamarin.Forms UWP应用上看到一个有线问题。这是使用.NETStandard 2的Xamarin跨平台应用程序,因此代码不是特定于平台的,而是.NETStandard库(或在PCL之前称为的内容)的一部分。

我正在建立与服务器的TCPIP连接,并在Android,iOS和UWP的所有三个平台上成功从服务器获取一些数据。

这一切都很好,而且可行。

我看到的问题有点愚蠢。我是Xamarin编辑器控件,用于显示服务器的输出。编辑器控件应该展开以显示添加到其中的所有新文本。它在Android或iOS上执行此操作,但在UWP上不执行。更甚者,在UWP上,收到的消息中未显示任何文本,但消息已成功接收,我可以通过在下面的msg变量或在editorResponse.Text属性上咆哮来在调试模式下看到它

private void ReadResponse()
{
    if (serverStream.CanRead)
    {
        byte[] readBuffer = new byte[1024];
        StringBuilder receivedMessage = new StringBuilder();
        int readSoFar = 0;

        do
        {
            //serverSteam is an instance of System.Net.Sockets.NetworkStream
            readSoFar = serverStream.Read(readBuffer, 0, readBuffer.Length);
            receivedMessage.AppendFormat("{0}", Encoding.ASCII.GetString(readBuffer, 0, readSoFar));
        } 
        while (serverStream.DataAvailable);

        string msg = receivedMessage.ToString().Trim();

        //PROBLEM IS HERE AND ON UWP ONLY!  BOTH IOS AND ANDROID ARE FINE
        //hower over msg or editorResponse.Text
        //and I see both have correct received 
        //information from server but editorResponse Editor 
        //control wont show it
        //Hardcoding dummy string will show correct however
        editorResponse.Text = msg; // this is Xamarin Editor view

        //If I put message into a Label control, it shows just fine
        lblResponse.Text = msg;  // this works!
    }
    else
    {
        DisplayAlert("Error", "Cannot read from NetworkStream", "Close");
    }
}

这是在XAML中设置我的编辑器的方式

    <Editor x:Name="editorResponse" 
        Text="Server response will show here"
        AutoSize="TextChanges"
        IsSpellCheckEnabled="False"
        HorizontalOptions="Fill"
        VerticalOptions="Fill">
    </Editor>

0 个答案:

没有答案