Windows Phone - 无法返回我自己的应用程序.SmsComposeTask启动程序

时间:2015-08-10 22:31:31

标签: c# silverlight windows-phone-8.1 contacts launcher

我正在创建一个Windows Phone 8.1 Silverlight应用程序。

当我称这种方法时:

private void btn_send_Click(object sender, EventArgs e)
{
    object o;
    ContactData dane = null;
    if (PhoneApplicationService.Current.State.TryGetValue("Contact", out o))
    {
        dane = o as ContactData;
        SmsComposeTask objSendsms = new SmsComposeTask();
        objSendsms.To = (dane.Number).ToString();
        objSendsms.Body = input.Text.ToString();
        objSendsms.Show();
    }
}

然后如果只想我想做的就是按key_back按钮: this_photo_will_show

我知道在调用btn_send_Click之后,此函数将打开Microsoft应用程序的新实例。更具体地说,它将是来自.Show对象的此函数SmsComposeTask。但是如何与这个应用程序通信?如何使用key_back按钮返回我自己的应用程序?

1 个答案:

答案 0 :(得分:0)

最后我找到了一个决议。

1.更改课程中的字段

 [DataContract]
    public class ContactData
    {
        [DataMember]
       public byte[] Image
       {
           get;
           set;
       }

        public  byte[] ConvertToBytes(BitmapImage bitmapImage)
    {
        byte[] data = null;
        using (MemoryStream stream = new MemoryStream())
        {
            WriteableBitmap wBitmap = new WriteableBitmap(bitmapImage);
            wBitmap.SaveJpeg(stream, wBitmap.PixelWidth, wBitmap.PixelHeight, 0, 100);
            stream.Seek(0, SeekOrigin.Begin);
            data = stream.GetBuffer();
        }

        return data;
    }

  }

2.添加一个项目:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using System.Globalization;
using System.Windows;

namespace KontaktySilver
{
    public class BytesToImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

        {
            if (value != null && value is byte[])
            {
                byte[] bytes = value as byte[];
                using(MemoryStream stream = new MemoryStream(bytes)){
                BitmapImage image = new BitmapImage();

                image.SetSource(stream);
                MessageBox.Show("proba");
                return image;
                }
            }

            return null;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

    }
}

3.添加xmlns:local="clr-namespace:YourProjectName"

4.更改xaml中的绑定:

<Image Source="{Binding Image, Converter={StaticResource BytesToImageConverter}}"  Stretch="Fill" />