自定义消息框在windows phone 8中不显示

本文关键字:显示 phone windows 自定义消息 | 更新日期: 2023-09-27 17:51:05

我正在开发windows phone应用程序。我必须将图像转换为二进制数组,并且必须通过web服务(//一些代码)将这些细节发送到后端。所以这个过程花了一些时间。我放置这个自定义消息框是为了显示保存过程。但是没有显示这个自定义消息框。为什么会这样?

提前感谢。

private CustomMessageBox cmd;//global variable
private void Save_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtSignby.Text.ToString()) && MyIP.Strokes != null && MyIP.Strokes.Count > 0)
            {
                WriteableBitmap wbBitmap = new WriteableBitmap(MyIP, new TranslateTransform());
                EditableImage eiImage = new EditableImage(wbBitmap.PixelWidth, wbBitmap.PixelHeight);
                cmd = new CustomMessageBox()
                {
                    Caption = "SAVING....",
                    Message = "Please wait...."
                };
                cmd.Show();
                //some code
                //some code
                //some code
                //some code
                cmd.Dismiss();
}
}

自定义消息框类使用from Microsoft.Phone.Controls.Toolkit.dll

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace Microsoft.Phone.Controls
{
    [TemplatePart(Name = "CaptionTextBlock", Type = typeof(TextBlock))]
    [TemplatePart(Name = "LeftButton", Type = typeof(ButtonBase))]
    [TemplatePart(Name = "MessageTextBlock", Type = typeof(TextBlock))]
    [TemplatePart(Name = "RightButton", Type = typeof(ButtonBase))]
    [TemplatePart(Name = "TitleTextBlock", Type = typeof(TextBlock))]
    public class CustomMessageBox : ContentControl
    {
        public static readonly DependencyProperty CaptionProperty;
        public static readonly DependencyProperty IsFullScreenProperty;
        public static readonly DependencyProperty IsLeftButtonEnabledProperty;
        public static readonly DependencyProperty IsRightButtonEnabledProperty;
        public static readonly DependencyProperty LeftButtonContentProperty;
        public static readonly DependencyProperty MessageProperty;
        public static readonly DependencyProperty RightButtonContentProperty;
        public static readonly DependencyProperty TitleProperty;
        public CustomMessageBox();
        public string Caption { get; set; }
        public bool IsFullScreen { get; set; }
        public bool IsLeftButtonEnabled { get; set; }
        public bool IsRightButtonEnabled { get; set; }
        public object LeftButtonContent { get; set; }
        public string Message { get; set; }
        public object RightButtonContent { get; set; }
        public string Title { get; set; }
        public event EventHandler<DismissedEventArgs> Dismissed;
        public event EventHandler<DismissingEventArgs> Dismissing;
        public void Dismiss();
        public override void OnApplyTemplate();
        public void Show();
    }
}

自定义消息框在windows phone 8中不显示

您需要让UI线程运行一点以显示自定义消息框。一种方便的方法是使用async/await关键字:

private async void Save_Click(object sender, EventArgs e)
{
    if (!string.IsNullOrEmpty(txtSignby.Text.ToString()) && MyIP.Strokes != null && MyIP.Strokes.Count > 0)
    {
        WriteableBitmap wbBitmap = new WriteableBitmap(MyIP, new TranslateTransform());
        EditableImage eiImage = new EditableImage(wbBitmap.PixelWidth, wbBitmap.PixelHeight);
        cmd = new CustomMessageBox()
        {
            Caption = "SAVING....",
            Message = "Please wait...."
        };
        cmd.Show();
        await Task.Delay(10);
        //some code
        //some code
        //some code
        //some code
        cmd.Dismiss();
    }
}