按下鍵盤的return or next 鍵,可以自動跳到下一個TextField,並在最後一個TextField按下return or next 鍵後,會自動執行Default action

小賢 發表在 痞客邦 留言(0) 人氣()

 

小賢 發表在 痞客邦 留言(0) 人氣()

 

        private const string strKey = "Key";
        private const string strIV = "IV";

        public static string Encrypt(string message) 
        {
            if (string.IsNullOrEmpty(message))
            {
                return string.Empty;
            }

            var keyBuffer = CryptographicBuffer.ConvertStringToBinary(strKey, BinaryStringEncoding.Utf8);
            var ivBuffer = CryptographicBuffer.ConvertStringToBinary(strIV, BinaryStringEncoding.Utf8);
            var messageBuffer = CryptographicBuffer.ConvertStringToBinary(message, BinaryStringEncoding.Utf8);

            var provider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.DesCbcPkcs7);
            var key = provider.CreateSymmetricKey(keyBuffer);
            var buffEncrypt = CryptographicEngine.Encrypt(key, messageBuffer, ivBuffer);

            return CryptographicBuffer.EncodeToBase64String(buffEncrypt);
        }

        public static string Decrypt(string encryptedBase64String)
        {
            if (string.IsNullOrEmpty(encryptedBase64String))
            {
                return string.Empty;
            }

            var buffer = CryptographicBuffer.ConvertStringToBinary(strKey, BinaryStringEncoding.Utf8);
            var ivBuffer = CryptographicBuffer.ConvertStringToBinary(strIV, BinaryStringEncoding.Utf8);

            var provider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.DesCbcPkcs7);
            var keyBuffer = provider.CreateSymmetricKey(buffer);
            
            var decryptedBuffer = CryptographicEngine.Decrypt(keyBuffer, CryptographicBuffer.DecodeFromBase64String(encryptedBase64String), ivBuffer);
            return CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, decryptedBuffer);
        }

 

小賢 發表在 痞客邦 留言(0) 人氣()

想在App裡開啟其它App,在iOS 9需加入 "LSApplicationQueriesSchemes" 白名單。

 

小賢 發表在 痞客邦 留言(0) 人氣()

 

    public partial class TakePhotoPage
    {
        private MediaCapture _mediaCapture;
        private bool _isPreviewing;
        private DisplayRequest _displayRequest;

        private async Task StartPreviewAsync()
        {
            try
            {
                _mediaCapture = new MediaCapture();
                await _mediaCapture.InitializeAsync();

                PreviewControl.Source = _mediaCapture;
                await _mediaCapture.StartPreviewAsync();
                _isPreviewing = true;

                _displayRequest = new DisplayRequest();
                _displayRequest.RequestActive();
                DisplayInformation.AutoRotationPreferences = DisplayOrientations.PortraitFlipped;

                // 解決手機上的旋轉問題
                SimpleOrientationSensor sensor = SimpleOrientationSensor.GetDefault();
                if (sensor == null)
                {
                    return;
                }

                sensor.OrientationChanged += (s, arg) =>
                {
                    switch (arg.Orientation)
                    {
                        case SimpleOrientation.Rotated90DegreesCounterclockwise:
                            _mediaCapture.SetPreviewRotation(VideoRotation.None);
                            break;
                        case SimpleOrientation.Rotated180DegreesCounterclockwise:
                        case SimpleOrientation.Rotated270DegreesCounterclockwise:
                            _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise180Degrees);
                            break;
                        default:
                            _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
                            break;
                    }
                };

            }
            catch (UnauthorizedAccessException)
            {
                // This will be thrown if the user denied access to the camera in privacy settings
                var messageDialog = new MessageDialog("The app was denied access to the camera");
                await messageDialog.ShowAsync();
            }
            catch (Exception ex)
            {
                var messageDialog = new MessageDialog("MediaCapture initialization failed. {0}", ex.Message);
                await messageDialog.ShowAsync();
            }
        }

        private async Task CleanupCameraAsync()
        {
            if (_mediaCapture == null)
            {
                return;
            }

            if (_isPreviewing)
            {
                await _mediaCapture.StopPreviewAsync();
            }

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                PreviewControl.Source = null;

                if (_displayRequest == null)
                {
                    return;
                }

                _displayRequest.RequestRelease();
            });

            _mediaCapture.Dispose();
            _mediaCapture = null;

        }

    }

 

小賢 發表在 痞客邦 留言(0) 人氣()