【问题标题】:Windows Phone - Can't come back to my own application .SmsComposeTask launcherWindows Phone - 无法返回我自己的应用程序 .SmsComposeTask 启动器
【发布时间】:2015-11-02 23:58:23
【问题描述】:

我正在创建一个 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 应用程序实例。更具体地说,它将是来自SmsComposeTask 对象的这个函数.Show。但是如何与这个应用程序通信呢?如何使用key_back 按钮回到我自己的应用程序?

【问题讨论】:

  • 有什么异常? (中的e参数)
  • Microsoft.Phone.Interop.ni.dll 中出现“System.Runtime.Serialization.InvalidDataContractException”类型的未处理异常附加信息:“System.Windows.Media.ImageSource”类型无法序列化。考虑使用 DataContractAttribute 属性对其进行标记,并使用 DataMemberAttribute 属性标记您想要序列化的所有成员。或者,您可以确保该类型是公共的并且具有无参数的构造函数 - 然后该类型的所有公共成员都将被序列化,并且不需要任何属性。
  • 当我不加载图像时它可以工作..但我想加载我的图像; ) 我尝试使用 [DataContract] 和 [DataMember] 但仍然无法正常工作。
  • 现在我知道了。问题是当我将public BitmapImage Image { get; set; } 方法添加到我的公共类时。 . :(但是为什么?有人帮我吗?

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


【解决方案1】:

我终于找到了解决办法。

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" />

【讨论】:

    猜你喜欢
    • 2011-04-08
    • 1970-01-01
    • 2014-06-07
    • 1970-01-01
    • 1970-01-01
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-11-22
    相关资源
    最近更新 更多