有没有什么方法可以在没有点击的情况下调用方法img_Tapped(当我点击UI元素(按钮)时),但是从构造函数中调用它?我有MessageReceived的处理程序。如果没有人可以建议我如何为同一个函数重新制作这两个方法 - 我不需要点击元素这些方法应该在应用程序启动或页面加载时执行...
方法1:
private async void img_Tapped(object sender, TappedRoutedEventArgs e)
{
...
mws = new MessageWebSocket();
mws.Control.MessageType = SocketMessageType.Binary;
mws.MessageReceived += MessageReceived;
await mws.ConnectAsync(server);
messageWriter = new DataWriter(mws.OutputStream);
messageWriter.WriteBytes(buff);
await messageWriter.StoreAsync();
}
方法2:
private void MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args)
{
try
{
using (DataReader reader = args.GetDataReader())
{
reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
byte[] read = reader.ReadBuffer(reader.UnconsumedBufferLength).ToArray();
}
}
catch (Exception ex)
{
}
}
。 。
我发现这个但不好,因为仍然需要点击/点按按钮,我不想要它。
img.Tapped += new TappedEventHandler(my method with button parameters);