예제 #1
0
        private void ActivateEditTextImpl()
        {
            var pane = Windows.UI.ViewManagement.InputPane.GetForCurrentView();
            if (pane.TryShow())
            {
                var game = GetGame();
                if (game == null)
                    throw new ArgumentException("Provided services need to contain a provider for the IGame interface.");

                Debug.Assert(game.Context is GameContextUWP, "There is only one possible descendant of GameContext for Windows Store.");

                gameContext = (GameContextUWP)game.Context;
                var swapChainPanel = gameContext.Control;

                // Detach previous EditText (if any)
                if (activeEditText != null)
                    activeEditText.IsSelectionActive = false;
                activeEditText = this;

                // Make sure it doesn't have a parent (another text box being edited)
                editText = gameContext.EditTextBox;
                editText.Text = text;
                swapChainPanel.Children.Add(new Windows.UI.Xaml.Controls.StackPanel { Children = { editText } });

                editText.TextChanged += EditText_TextChanged;
                editText.KeyDown += EditText_KeyDown;

                // Focus
                editText.Focus(Windows.UI.Xaml.FocusState.Programmatic);
            }
        }
예제 #2
0
        private void ActivateEditTextImpl()
        {
            // try to show the virtual keyboard if no hardward keyboard available
            Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryShow();

            var game = GetGame();

            // Detach previous EditText (if any)
            if (activeEditText != null)
            {
                activeEditText.IsSelectionActive = false;
            }
            activeEditText = this;

            // Handle only GameContextUWPXaml for now
            // TODO: Implement EditText for GameContextUWPCoreWindow
            gameContext = game.Context as GameContextUWPXaml;
            if (gameContext == null)
            {
                return;
            }

            var swapChainPanel = gameContext.Control;

            // Make sure it doesn't have a parent (another text box being edited)
            editText      = gameContext.EditTextBox;
            editText.Text = text;
            swapChainPanel.Children.Add(new Windows.UI.Xaml.Controls.Grid {
                Children = { editText }, Opacity = 0.7f, Background = new SolidColorBrush(Colors.Black)
            });

            editText.TextChanged += EditText_TextChanged;
            editText.KeyDown     += EditText_KeyDown;
        }
예제 #3
0
        private void OnSofKeyboardHiding(Windows.UI.ViewManagement.InputPane sender, Windows.UI.ViewManagement.InputPaneVisibilityEventArgs args)
        {
            OnKeyboardWillHide();

            IsVisible = false;

            // Get our Current SwapChainPanel
            var content = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.SwapChainBackgroundPanel;

            if (content == null)
            {
                // Do our detach stuff
                return;
            }

            hiddenKeyInput.KeyDown -= OnKeyDown;
            hiddenKeyInput.KeyUp   -= OnKeyUp;

            // enable us
            hiddenKeyInput.IsEnabled = false;
            hiddenKeyInput.Focus(Windows.UI.Xaml.FocusState.Pointer);

            content.Children.Remove(hiddenKeyInput);

            hiddenKeyInput = null;

            keyboard.Hiding -= OnSofKeyboardHiding;

            OnKeyboardDidHide();
        }
예제 #4
0
파일: Shared.cs 프로젝트: pitush/numericUWP
 public cTxtBoxProperty(Windows.UI.Xaml.Controls.TextBox sender)
 {
     iBeg = sender.SelectionStart;
     iSel = sender.SelectionLength;
     iLen = sender.Text.Length;
     sLef = sender.Text.Substring(0, sender.SelectionStart);
     sRig = sender.Text.Substring(sender.SelectionStart + sender.SelectionLength);
     sSel = sender.SelectedText;
     sTxt = sender.Text;
 }
예제 #5
0
파일: Shared.cs 프로젝트: pitush/numericUWP
 /// <summary>
 /// Routine to test numeric if current TextChanging is numeric and display accordinly to current culture.
 /// </summary>
 /// <param name="sender">Target TextBox</param>
 /// <param name="pattern">Currently only Numeric Pattern is supported eg: "N2", "N6"...etc. N stands for number.</param>
 /// <param name="numbersOnly">true = allow numbers only; false = leave text if its not numeric decimal.</param>
 /// <param name="dotAsDecimalSeparator">true = "." counts as decimal separator (regardless of culture) and it will go for decimal part of pattern (if any).</param>
 /// <param name="allowNegativeNumbers">true = can have negative numbers, false = prevents negative numbers.</param>
 /// <param name="lstRemoveStrings">List of any other strings you wish remove eg: "(", " / ", ")", " - ", " + "...etc, if none just pass "null" parameter.</param>
 /// <param name="anyTag">Use paramenter to pass some object in Tag, if none just pass "null" parameter.</param>
 public ClsNumTextTagIn(Windows.UI.Xaml.Controls.TextBox sender, string pattern, bool numbersOnly, bool dotAsDecimalSeparator, bool allowNegativeNumbers, System.Collections.Generic.List <string> lstRemoveStrings, System.Object anyTag)
 {
     org       = new cTxtBoxProperty(sender);
     MyPattern = pattern;
     IsNumOnly = numbersOnly;
     IsDotSepa = dotAsDecimalSeparator;
     CanNegNum = allowNegativeNumbers;
     LstRemStr = lstRemoveStrings;
     Tag       = anyTag; //use this Tag
 }
예제 #6
0
        protected override HandleRef BuildWindowCore(HandleRef hwndParent)
        {
            Win32Interop.EnableMouseInPointer();

            // There are several different low-level interfaces available at this time.
            // Use XamlBridge unless you have a known reason to use the others.
            //IntPtr windowHandle = InitializePresenterHwndMode(hwndParent);
            //IntPtr windowHandle = InitializePresenterCoreWindowMode(hwndParent);
            IntPtr windowHandle = InitializeBridge(hwndParent);

            // Uncomment the following lines to create Xaml UI content directly from within this WPF host control.
            // Normally, the user of this control sets a property which is the name of a Xaml UserControl to instantiate.

            Windows.UI.Xaml.Controls.StackPanel panel = new Windows.UI.Xaml.Controls.StackPanel();
            panel.Orientation = Windows.UI.Xaml.Controls.Orientation.Vertical;
            panel.Background  = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red);

            Windows.UI.Xaml.Controls.TextBox textBox = new Windows.UI.Xaml.Controls.TextBox();
            textBox.Text = "XAML TextBox 1";
            panel.Children.Add(textBox);

            Windows.UI.Xaml.Controls.Button button = new Windows.UI.Xaml.Controls.Button();
            button.Content = "XAML Button";
            panel.Children.Add(button);

            textBox      = new Windows.UI.Xaml.Controls.TextBox();
            textBox.Text = "XAML TextBox 2";
            panel.Children.Add(textBox);

            //XamlClassLibrary.TestUserControl testUserControl = new XamlClassLibrary.TestUserControl();
            //panel.Children.Add(testUserControl);

            Windows.UI.Xaml.Window.Current.Content = panel;

            panel.LayoutUpdated += XamlContentLayoutUpdated;


            XamlApplication application        = new XamlApplication();
            String          globalResourceFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "globalresources.xbf");

            if (File.Exists(globalResourceFile))
            {
                Windows.UI.Xaml.Application.LoadComponent(application, new Uri("ms-resource:///Files/globalresources.xaml"));
            }

            Windows.UI.Xaml.FrameworkElement contentRoot = panel;
            //var type = Type.GetType(ControlType, true, true);
            //Windows.UI.Xaml.FrameworkElement contentRoot = (Windows.UI.Xaml.FrameworkElement) Activator.CreateInstance("XamlClassLibrary", ControlType).Unwrap();

            Windows.UI.Xaml.Window.Current.Content = contentRoot;

            contentRoot.LayoutUpdated += XamlContentLayoutUpdated;

            return(new HandleRef(this, windowHandle));
        }
예제 #7
0
        /// <summary>
        /// A new Windows.UI.Xaml.TextBox
        /// </summary>
        /// <returns>Windows.UI.Xaml.TextBox</returns>
        internal WUX.Controls.Control GetTextBox()
        {
            var textBox = new WUX.Controls.TextBox()
            {
                Width  = 300,
                Margin = new WUX.Thickness(0, 10, 0, 0),
                HorizontalAlignment = WUX.HorizontalAlignment.Left,
            };

            return(textBox);
        }
예제 #8
0
        private void DeactivateEditTextImpl()
        {
            if (editText != null)
            {
                // Remove text box
                editText.TextChanged -= EditText_TextChanged;
                editText.KeyDown     -= EditText_KeyDown;
                var stackPanel = (Windows.UI.Xaml.Controls.Panel)editText.Parent;
                stackPanel.Children.Remove(editText);
                gameContext.Control.Children.Remove(stackPanel);

                editText       = null;
                activeEditText = null;
            }

            FocusedElement = null;
        }
예제 #9
0
        private void ActivateEditTextImpl()
        {
            var pane = Windows.UI.ViewManagement.InputPane.GetForCurrentView();

            if (pane.TryShow())
            {
                var game = GetGame();
                if (game == null)
                {
                    throw new ArgumentException("Provided services need to contain a provider for the IGame interface.");
                }

                // Detach previous EditText (if any)
                if (activeEditText != null)
                {
                    activeEditText.IsSelectionActive = false;
                }
                activeEditText = this;

                // Handle only GameContextUWPXaml for now
                // TODO: Implement EditText for GameContextUWPCoreWindow
                gameContext = game.Context as GameContextUWPXaml;
                if (gameContext == null)
                {
                    return;
                }

                var swapChainPanel = gameContext.Control;

                // Make sure it doesn't have a parent (another text box being edited)
                editText      = gameContext.EditTextBox;
                editText.Text = text;
                swapChainPanel.Children.Add(new Windows.UI.Xaml.Controls.StackPanel {
                    Children = { editText }
                });

                editText.TextChanged += EditText_TextChanged;
                editText.KeyDown     += EditText_KeyDown;

                // Focus
                editText.Focus(Windows.UI.Xaml.FocusState.Programmatic);
            }
        }
예제 #10
0
파일: Util.cs 프로젝트: ckc/WinApp
        internal static void GotoEndPosTextBox(Windows.UI.Xaml.Controls.TextBox textBox)
        {
            var count = Windows.UI.Xaml.Media.VisualTreeHelper.GetChildrenCount(textBox);

            for (int i = 0; i < count; i++)
            {
                var child     = Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(textBox, i);
                var morecount = Windows.UI.Xaml.Media.VisualTreeHelper.GetChildrenCount(child);
                for (int j = 0; j < morecount; j++)
                {
                    var grandchild = Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(child, j);
                    var scroll     = grandchild as Windows.UI.Xaml.Controls.ScrollViewer;
                    if (scroll != null)
                    {
                        scroll.ChangeView(null, scroll.ExtentHeight, null);
                        return;
                    }
                }
            }
        }
예제 #11
0
        private void ActivateEditTextImpl()
        {
            // Windows Store don't have this method, so let's always use TextBox
#if !SILICONSTUDIO_PLATFORM_WINDOWS_STORE
            var pane = Windows.UI.ViewManagement.InputPane.GetForCurrentView();
            if (pane.TryShow())
#endif
            {
                var game = GetGame();
                if (game == null)
                {
                    throw new ArgumentException("Provided services need to contain a provider for the IGame interface.");
                }

                Debug.Assert(game.Context is GameContextWindowsRuntime, "There is only one possible descendant of GameContext for Windows Store.");

                gameContext = (GameContextWindowsRuntime)game.Context;
                var swapChainPanel = gameContext.Control;

                // Detach previous EditText (if any)
                if (activeEditText != null)
                {
                    activeEditText.IsSelectionActive = false;
                }
                activeEditText = this;

                // Make sure it doesn't have a parent (another text box being edited)
                editText      = gameContext.EditTextBox;
                editText.Text = text;
                swapChainPanel.Children.Add(new Windows.UI.Xaml.Controls.StackPanel {
                    Children = { editText }
                });

                editText.TextChanged += EditText_TextChanged;
                editText.KeyDown     += EditText_KeyDown;

                // Focus
                editText.Focus(Windows.UI.Xaml.FocusState.Programmatic);
            }
        }
예제 #12
0
        public void BenefitTextBox_TextChanging(Windows.UI.Xaml.Controls.TextBox sender, Windows.UI.Xaml.Controls.TextBoxTextChangingEventArgs args)
        {
            switch (sender.Name)
            {
            case "Benefit1TextBox":
                CurrentBenefitCollection[0].BenefitText = sender.Text;
                break;

            case "Benefit1TitleBox":
                CurrentBenefitCollection[0].BenefitLabel = sender.Text;
                break;

            case "Benefit2TextBox":
                CurrentBenefitCollection[1].BenefitText = sender.Text;
                break;

            case "Benefit2TitleBox":
                CurrentBenefitCollection[1].BenefitLabel = sender.Text;
                break;

            case "Benefit3TextBox":
                CurrentBenefitCollection[2].BenefitText = sender.Text;
                break;

            case "Benefit3TitleBox":
                CurrentBenefitCollection[2].BenefitLabel = sender.Text;
                break;

            case "Benefit4TextBox":
                CurrentBenefitCollection[3].BenefitText = sender.Text;
                break;

            case "Benefit4TitleBox":
                CurrentBenefitCollection[3].BenefitLabel = sender.Text;
                break;
            }
        }
예제 #13
0
 public static string GetRealTimeText(Windows.UI.Xaml.Controls.TextBox obj)
 {
     return((string)obj.GetValue(RealTimeTextProperty));
 }
예제 #14
0
        public bool ShowKeyboardInput()
        {
            keyboard.Hiding  += OnSofKeyboardHiding;
            keyboard.Showing += OnSofKeyboardShowing;

            // RunAsync all of the UI info.
            dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                // Create a TextBox that will be added to our view but hidden
                hiddenKeyInput         = new Windows.UI.Xaml.Controls.TextBox();
                hiddenKeyInput.Opacity = 0;

                // We will only be generating one character at a time and does not
                // matter about the font.  All we need is the text.
                hiddenKeyInput.Width    = 1;
                hiddenKeyInput.Height   = 1;
                hiddenKeyInput.MaxWidth = 1;

                // Create an input scope for us.  Probably not needed
                var scope = new Windows.UI.Xaml.Input.InputScope();
                var name  = new Windows.UI.Xaml.Input.InputScopeName();

                name.NameValue = Windows.UI.Xaml.Input.InputScopeNameValue.Default;
                scope.Names.Add(name);

                hiddenKeyInput.InputScope = scope;

                // Set spell checking off.
                hiddenKeyInput.IsSpellCheckEnabled = false;

                // Get our Current SwapChainPanel.  This is for our WP8.1 implementation
                var content = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.SwapChainBackgroundPanel;
                if (content == null)
                {
                    // Do our detach stuff
                    DetachWithIME();
                    return;
                }

                // Add our hidden TextBox to our panel
                content.Children.Add(hiddenKeyInput);

                // Hook up our key delegates
                hiddenKeyInput.KeyDown += OnKeyDown;
                hiddenKeyInput.KeyUp   += OnKeyUp;

                // enable us and set focus
                hiddenKeyInput.IsEnabled = true;
                hiddenKeyInput.Focus(Windows.UI.Xaml.FocusState.Programmatic);

                // Show the soft keyboard if possible
                var didShow = keyboard.TryShow();
                if (!didShow)
                {
                    DetachWithIME();
                }

                //CCLog.Log("we be in background");
            }
                                );

            return(true);
        }
예제 #15
0
        private void DeactivateEditTextImpl()
        {
            if (editText != null)
            {
                // Remove text box
                editText.TextChanged -= EditText_TextChanged;
                editText.KeyDown -= EditText_KeyDown;
                var stackPanel = (Windows.UI.Xaml.Controls.Panel)editText.Parent;
                stackPanel.Children.Remove(editText);
                gameContext.Control.Children.Remove(stackPanel);

                editText = null;
                activeEditText = null;
            }

            FocusedElement = null;
        }
예제 #16
0
 public static void SetRealTimeText(Windows.UI.Xaml.Controls.TextBox obj, string value)
 {
     obj.SetValue(RealTimeTextProperty, value);
 }
예제 #17
0
 public static bool GetIsAutoUpdate(Windows.UI.Xaml.Controls.TextBox obj)
 {
     return((bool)obj.GetValue(IsAutoUpdateProperty));
 }
예제 #18
0
파일: Shared.cs 프로젝트: pitush/numericUWP
 public void Refresh(Windows.UI.Xaml.Controls.TextBox sender)
 {
     org = new cTxtBoxProperty(sender);
 }
예제 #19
0
 public static void SetIsAutoUpdate(Windows.UI.Xaml.Controls.TextBox obj, bool value)
 {
     obj.SetValue(IsAutoUpdateProperty, value);
 }
예제 #20
0
파일: Shared.cs 프로젝트: pitush/numericUWP
        public void NumericText(Windows.UI.Xaml.Controls.TextBox sender)
        { //logics
            if (org == null)
            {
                org = new cTxtBoxProperty(sender);
            }

            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentUICulture;
            cTxtBoxProperty edi  = new cTxtBoxProperty(sender);
            string          sPtn = MyPattern;
            string          sAdd = string.Empty;
            string          sSub = string.Empty;
            int             iChg = edi.iLen - org.iBeg - org.sRig.Length;

            if (iChg >= 0)
            {
                sAdd = edi.sTxt.Substring(org.iBeg, iChg);
                sSub = org.sSel;
            }
            else
            { //backspace?
                if (org.iLen >= edi.iLen)
                {
                    if (org.iBeg - (org.iLen - edi.iLen) >= 0)
                    {
                        sSub = org.sTxt.Substring(org.iBeg - (org.iLen - edi.iLen), (org.iLen - edi.iLen));
                    }
                }
            }

            int    iBgx = edi.iBeg;
            int    iSlx = 0;
            string sFnl = org.sTxt;

            int iNeg = sFnl.IndexOf(ci.NumberFormat.NegativeSign);
            int iDot = sFnl.IndexOf(ci.NumberFormat.NumberDecimalSeparator);

            if (sAdd == ci.NumberFormat.NegativeSign)
            {
                if (iNeg == -1)
                {     //add
                    if (CanNegNum)
                    { //accepts negative numbers
                        if (ci.TextInfo.IsRightToLeft)
                        {
                            sFnl = sFnl + ci.NumberFormat.NegativeSign;
                            iBgx = edi.iBeg - ci.NumberFormat.NegativeSign.Length;
                        }
                        else
                        {
                            sFnl = ci.NumberFormat.NegativeSign + sFnl;
                            //iBgx = edi.iBeg;
                        }
                    }
                    else
                    {//does not accepts negative numbers
                        if (ci.TextInfo.IsRightToLeft)
                        {
                            iBgx = edi.iBeg - ci.NumberFormat.NegativeSign.Length;
                        }
                        else
                        {
                            iBgx = edi.iBeg;
                        }
                    }
                }
                else
                {//remove
                    sFnl = sFnl.Remove(iNeg, ci.NumberFormat.NegativeSign.Length);
                    if (iNeg >= iBgx)
                    {
                        iBgx = edi.iBeg - ci.NumberFormat.NegativeSign.Length;
                    }
                    else
                    {
                        if (ci.TextInfo.IsRightToLeft)
                        {
                            iBgx = edi.iBeg - ci.NumberFormat.NegativeSign.Length;
                        }
                        else
                        {
                            iBgx = edi.iBeg - ci.NumberFormat.NegativeSign.Length - ci.NumberFormat.NegativeSign.Length;
                        }
                    }
                }
            } //end NegativeSign
            else if (sAdd == ci.NumberFormat.NumberDecimalSeparator)
            { //NumberDecimalSeparator
                if (iDot == -1)
                { //add
                    sFnl = edi.sTxt;
                }
                else
                { //go to point
                    sFnl = org.sTxt;
                    iBgx = iDot + ci.NumberFormat.NumberDecimalSeparator.Length;
                }
            }
            else if (sAdd == ".")
            { //dotAsDecimalSeparator
                if (IsDotSepa)
                {
                    if (iDot == -1)
                    { //add
                        sFnl = edi.sTxt;
                    }
                    else
                    { //go to point
                        sFnl = org.sTxt;
                        iBgx = iDot + ci.NumberFormat.NumberDecimalSeparator.Length;
                    }
                }
                else
                {
                    sFnl = edi.sTxt; //override
                }
            }
            else if (sSub == ci.NumberFormat.NumberGroupSeparator & org.iSel == 0)
            { //backspace and GroupSeparator
                if (edi.iBeg == 0)
                {
                    sFnl = edi.sTxt;
                }
                else
                {
                    sFnl = edi.sLef.Replace(ci.NumberFormat.NumberGroupSeparator, string.Empty);
                    int iRem = edi.sLef.Length - sFnl.Length;
                    sFnl = sFnl.Substring(0, edi.sLef.Length - iRem - 1) + edi.sRig;
                    iBgx = iBgx - iRem - 1;
                }
            }//end backspace and GroupSeparator
            else
            {
                sFnl = edi.sTxt;
            }

            if (iBgx > sFnl.Length)
            {
                iBgx = sFnl.Length;
            }
            string sLfx = sFnl.Substring(0, iBgx);
            string sRgx = sFnl.Substring(iBgx);

            sRgx = sRgx.Replace(ci.NumberFormat.NumberGroupSeparator, string.Empty);
            sFnl = sFnl.Replace(ci.NumberFormat.NumberGroupSeparator, string.Empty);

            if (LstRemStr != null)
            {
                foreach (string sRem in LstRemStr)
                {
                    sRgx = sRgx.Replace(sRem, string.Empty); //automatically trimmed
                    sFnl = sFnl.Replace(sRem, string.Empty); //automatically trimmed
                }
            }

            //s += "Rgx: " + sRgx.ToString() + Environment.NewLine;
            //s += "Fnl: " + sFnl.ToString() + Environment.NewLine;

            if (!CanNegNum)
            {//remove negative sign
                sRgx = sRgx.Replace(ci.NumberFormat.NegativeSign, string.Empty);
                sFnl = sFnl.Replace(ci.NumberFormat.NegativeSign, string.Empty);
            }

            decimal dFnl = decimal.Zero;
            decimal dRgx = decimal.Zero;

            if (decimal.TryParse(sFnl, out dFnl))
            {
                int iDtx = sFnl.IndexOf(ci.NumberFormat.NumberDecimalSeparator);
                int iDif = sFnl.Length - dFnl.ToString().Length;

                if (iDtx == -1)
                {//DecimalSeparator does not exist
                    sFnl = dFnl.ToString(sPtn);
                    int iTmp = sFnl.IndexOf(ci.NumberFormat.NumberDecimalSeparator);
                    if (iTmp == -1)
                    {//DecimalSeparator not found after apply pattern
                        if (sRgx == string.Empty)
                        {
                            iBgx = sFnl.Length;
                        }
                        else
                        {
                            if (sRgx.StartsWith(decimal.Zero.ToString()))
                            {
                                sRgx = decimal.One.ToString() + sRgx;
                                if (decimal.TryParse(sRgx, out dRgx))
                                {
                                    sRgx = dRgx.ToString(sPtn);
                                    if (sRgx.StartsWith(decimal.One.ToString() + ci.NumberFormat.NumberDecimalSeparator))
                                    {
                                        iBgx = sFnl.Length - sRgx.Length + (decimal.One.ToString() + ci.NumberFormat.NumberDecimalSeparator).Length;
                                    }
                                    else
                                    {
                                        iBgx = sFnl.Length - sRgx.Length + decimal.One.ToString().Length;
                                    }
                                }
                            }
                            else
                            {
                                if (decimal.TryParse(sRgx, out dRgx))
                                {
                                    sRgx = dRgx.ToString(sPtn);
                                    iBgx = sFnl.Length - sRgx.Length;
                                }
                            }
                        }
                    }
                    else
                    {//DecimalSeparator found after apply pattern
                        if (sRgx == string.Empty)
                        {
                            iBgx = iTmp;
                        }
                        else
                        {
                            if (sRgx.StartsWith(decimal.Zero.ToString()))
                            {
                                sRgx = decimal.One.ToString() + sRgx;
                                if (decimal.TryParse(sRgx, out dRgx))
                                {
                                    sRgx = dRgx.ToString(sPtn);
                                    if (sRgx.StartsWith(decimal.One.ToString() + ci.NumberFormat.NumberDecimalSeparator))
                                    {
                                        iBgx = sFnl.Length - sRgx.Length + (decimal.One.ToString() + ci.NumberFormat.NumberDecimalSeparator).Length;
                                    }
                                    else
                                    {
                                        iBgx = sFnl.Length - sRgx.Length + decimal.One.ToString().Length;
                                    }
                                }
                            }
                            else
                            {
                                if (decimal.TryParse(sRgx, out dRgx))
                                {
                                    sRgx = dRgx.ToString(sPtn);
                                    iBgx = sFnl.Length - sRgx.Length;
                                }
                            }
                        }
                    }

                    if (iBgx < 0)
                    {
                        iBgx = 0;
                    }
                }
                else
                {     //DecimalSeparator does exist
                    if (sFnl.Length - sRgx.Length <= iDtx)
                    { //before DecimalSeparator
                        sFnl = dFnl.ToString(sPtn);
                        if (sRgx.StartsWith(decimal.Zero.ToString()))
                        {
                            sRgx = decimal.One.ToString() + sRgx;
                            if (decimal.TryParse(sRgx, out dRgx))
                            {
                                sRgx = dRgx.ToString(sPtn);
                                if (sRgx.StartsWith(decimal.One.ToString() + ci.NumberFormat.NumberDecimalSeparator))
                                {
                                    iBgx = sFnl.Length - sRgx.Length + (decimal.One.ToString() + ci.NumberFormat.NumberDecimalSeparator).Length;
                                }
                                else
                                {
                                    iBgx = sFnl.Length - sRgx.Length + decimal.One.ToString().Length;
                                }
                            }
                        }
                        else if (sRgx.StartsWith(ci.NumberFormat.NumberDecimalSeparator))
                        {
                            if (decimal.TryParse(sRgx, out dRgx))
                            {
                                sRgx = dRgx.ToString(sPtn);
                                iBgx = sFnl.Length - sRgx.Length + ci.NumberFormat.NumberDecimalSeparator.Length;
                            }
                        }
                        else
                        {
                            if (decimal.TryParse(sRgx, out dRgx))
                            {
                                sRgx = dRgx.ToString(sPtn);
                                iBgx = sFnl.Length - sRgx.Length;
                            }
                        }

                        if (iBgx < 0)
                        {
                            iBgx = 0;
                        }
                    }
                    else
                    {                                                                    //after DecimalSeparator
                        sFnl = dFnl.ToString(sPtn);
                        int iTmp = sFnl.IndexOf(ci.NumberFormat.NumberDecimalSeparator); //override
                        if (iTmp == -1)
                        {                                                                // pattern does not accept DecimalSeparator
                            iBgx = sFnl.Length;
                        }
                        else
                        {
                            if (sSub != string.Empty & sAdd == string.Empty)
                            {// if backspace (after decimal separator)
                                if (iTmp + 1 < iBgx)
                                {
                                    iBgx = iBgx - 1;
                                }
                                else
                                {
                                    iBgx = iTmp;
                                }
                            }

                            if (sFnl.Length > iBgx)
                            {
                                if (iBgx > iTmp)
                                {
                                    iSlx = 1;
                                }
                            }
                        }
                    }
                }
                sender.Text            = sFnl;
                sender.SelectionStart  = iBgx;
                sender.SelectionLength = iSlx;
            }//end of if decimal
            else
            {//not decimal
                if (IsNumOnly)
                { //IsNumOnly =true
                    decimal dOrg = decimal.Zero;
                    if (sFnl != string.Empty && decimal.TryParse(org.sTxt, out dOrg))
                    {
                        sender.Text            = org.sTxt;
                        sender.SelectionStart  = org.iBeg;
                        sender.SelectionLength = org.iSel;
                    }
                    else
                    {
                        decimal dAdd = decimal.Zero;
                        decimal.TryParse(sAdd, out dAdd);
                        sFnl = dAdd.ToString(sPtn);
                        int iTmp = sFnl.IndexOf(ci.NumberFormat.NumberDecimalSeparator);

                        if (iTmp == -1)
                        {
                            iBgx = sFnl.Length;
                        }
                        else
                        {
                            iBgx = iTmp;
                        }
                        sender.Text            = sFnl;
                        sender.SelectionStart  = iBgx;
                        sender.SelectionLength = 0;
                    }
                }
                else
                { //numbersOnly false
                    sender.Text            = edi.sTxt;
                    sender.SelectionStart  = edi.iBeg;
                    sender.SelectionLength = edi.iSel;
                }
            }
        }
예제 #21
0
        private void OnSofKeyboardHiding(Windows.UI.ViewManagement.InputPane sender, Windows.UI.ViewManagement.InputPaneVisibilityEventArgs args)
        {
            OnKeyboardWillHide();

            IsVisible = false;

            // Get our Current SwapChainPanel
            var content = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.SwapChainBackgroundPanel;
            if (content == null)
            {
                // Do our detach stuff
                return;
            }

            hiddenKeyInput.KeyDown -= OnKeyDown;
            hiddenKeyInput.KeyUp -= OnKeyUp;

            // enable us
            hiddenKeyInput.IsEnabled = false;
            hiddenKeyInput.Focus(Windows.UI.Xaml.FocusState.Pointer);

            content.Children.Remove(hiddenKeyInput);

            hiddenKeyInput = null;

            keyboard.Hiding -= OnSofKeyboardHiding;

            OnKeyboardDidHide();
        }
예제 #22
0
        public bool ShowKeyboardInput()
        {

            keyboard.Hiding += OnSofKeyboardHiding;
            keyboard.Showing += OnSofKeyboardShowing;

            // RunAsync all of the UI info.
            dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {

                    // Create a TextBox that will be added to our view but hidden
                    hiddenKeyInput = new Windows.UI.Xaml.Controls.TextBox();
                    hiddenKeyInput.Opacity = 0;

                    // We will only be generating one character at a time and does not
                    // matter about the font.  All we need is the text.
                    hiddenKeyInput.Width = 1;
                    hiddenKeyInput.Height = 1;
                    hiddenKeyInput.MaxWidth = 1;

                    // Create an input scope for us.  Probably not needed
                    var scope = new Windows.UI.Xaml.Input.InputScope();
                    var name = new Windows.UI.Xaml.Input.InputScopeName();

                    name.NameValue = Windows.UI.Xaml.Input.InputScopeNameValue.Default;
                    scope.Names.Add(name);

                    hiddenKeyInput.InputScope = scope;

                    // Set spell checking off.
                    hiddenKeyInput.IsSpellCheckEnabled = false;

                    // Get our Current SwapChainPanel.  This is for our WP8.1 implementation
                    var content = Windows.UI.Xaml.Window.Current.Content as Windows.UI.Xaml.Controls.SwapChainBackgroundPanel;
                    if (content == null)
                    {
                        // Do our detach stuff
                        DetachWithIME();
                        return;
                    }

                    // Add our hidden TextBox to our panel
                    content.Children.Add(hiddenKeyInput);
                    
                    // Hook up our key delegates
                    hiddenKeyInput.KeyDown += OnKeyDown;
                    hiddenKeyInput.KeyUp += OnKeyUp;

                    // enable us and set focus
                    hiddenKeyInput.IsEnabled = true;
                    hiddenKeyInput.Focus(Windows.UI.Xaml.FocusState.Programmatic);

                    // Show the soft keyboard if possible
                    var didShow = keyboard.TryShow();
                    if (!didShow)
                    { 
                        DetachWithIME();
                    }

                    //CCLog.Log("we be in background");
            }
                );

            return true;
        }
예제 #23
0
        public static async void OpenInputDialog(string title, Action <string> callback, int max_length = 0, object[] args = null)
        {
            if (PlatformFunctions.IsDialogOpen)
            {
                return;
            }

            PlatformFunctions.IsDialogOpen = true;
            string result = "";

            Engine.Pause();
#if ANDROID
            var builder = new Android.App.AlertDialog.Builder(NeonPartyGamesControllerGame.AndroidContext);
            var input   = new Android.Widget.EditText(NeonPartyGamesControllerGame.AndroidContext);
            var tcs     = new System.Threading.Tasks.TaskCompletionSource <bool>();

            builder.SetTitle(title);
            if (args != null && args.Length > 0)
            {
                input.InputType = (Android.Text.InputTypes)args[0];
            }
            else
            {
                input.InputType = Android.Text.InputTypes.ClassText;
            }
            if (max_length > 0)
            {
                input.SetFilters(new Android.Text.IInputFilter[] { new Android.Text.InputFilterLengthFilter(max_length) });
            }
            builder.SetView(input);
            builder.SetPositiveButton("OK", (sender_alert, sender_args) => {
                VibrationHelper.Vibrate();
                result = input.Text;
            });
            builder.SetOnDismissListener(new OnDismissListener(() => tcs.TrySetResult(true)));
            builder.Show();
            await tcs.Task;
#elif IOS
            var tcs = new System.Threading.Tasks.TaskCompletionSource <bool>();
            UIKit.UIAlertView alert = new UIKit.UIAlertView();
            alert.Title = title;
            alert.AddButton("OK");
            alert.AlertViewStyle = UIKit.UIAlertViewStyle.PlainTextInput;
            alert.Clicked       += (object s, UIKit.UIButtonEventArgs ev) => {
                if (ev.ButtonIndex == 0)
                {
                    result = alert.GetTextField(0).Text;
                }
            };
            alert.Dismissed += (object s, UIKit.UIButtonEventArgs ev) => {
                tcs.TrySetResult(true);
            };
            alert.Show();
            await tcs.Task;
#elif NETFX_CORE
            await Xamarin.Essentials.MainThread.InvokeOnMainThreadAsync(async() =>
            {
                var input_text_box = new Windows.UI.Xaml.Controls.TextBox
                {
                    AcceptsReturn = false,
                    Height        = 32
                };
                if (max_length > 0)
                {
                    input_text_box.MaxLength = max_length;
                }
                var dialog = new Windows.UI.Xaml.Controls.ContentDialog
                {
                    Content                  = input_text_box,
                    Title                    = title,
                    PrimaryButtonText        = "Ok",
                    IsSecondaryButtonEnabled = true,
                    SecondaryButtonText      = "Cancel",
                    DefaultButton            = Windows.UI.Xaml.Controls.ContentDialogButton.Primary
                };
                if (await dialog.ShowAsync() == Windows.UI.Xaml.Controls.ContentDialogResult.Primary)
                {
                    result = input_text_box.Text;
                }
                else
                {
                    result = "";
                }
            });
#else
        #if DEBUG
            await System.Threading.Tasks.Task.Run(() => {
                var debugger = Engine.GetFirstInstanceByType <DebuggerWithTerminal>();
                debugger?.OpenConsoleWithCustomEvaluator(value => result = value);
                while (debugger != null && debugger.ConsoleOpen)
                {
                    System.Threading.Thread.Sleep(1);
                }
            });
        #endif
#endif
            Engine.Resume();
            PlatformFunctions.IsDialogOpen = false;

            if (!string.IsNullOrWhiteSpace(result))
            {
                callback?.Invoke(result);
            }
        }