private void addImage_Tapped(object sender, TappedRoutedEventArgs e)
 {
     numIngredients++;
     TextBox newTxtBox = new TextBox();
     newTxtBox.Name = "Ingredient"+ numIngredients;
     newTxtBox.Margin = new Thickness(10, 0, 0, 0);
     if (!flagColumn)
     {
         newTxtBox.SetValue(Grid.RowProperty, addImage.GetValue(Grid.RowProperty));
         newTxtBox.SetValue(Grid.ColumnProperty, 0);
         IngredientsGrid.RowDefinitions.Add(new RowDefinition());
         addImage.SetValue(Grid.RowProperty, ((int)addImage.GetValue(Grid.RowProperty) + 1));
     }
     else
     {
         newTxtBox.SetValue(Grid.RowProperty, lastRow);
         newTxtBox.SetValue(Grid.ColumnProperty, 1);
         lastRow++;
     }
     IngredientsGrid.Children.Remove(addImage);
     IngredientsGrid.UpdateLayout();
     IngredientsGrid.Children.Add(newTxtBox);
     IngredientsGrid.UpdateLayout();
     IngredientsGrid.Children.Add(addImage);
     IngredientsGrid.UpdateLayout();
     IngredientsPanel.UpdateLayout();
     numberTxtBox++;
     if(numberTxtBox % 4 == 0)
     {
         flagColumn = !flagColumn;
     }
    // IngredientsPanel.Children.Add(addImage);
 }
Example #2
0
 public TextBoxHelper(TextBox textBox)
 {
     textBox.TextChanged += (o, a) =>
         {
             textBox.SetValue(BindableTextProperty, textBox.Text);
         };
 }
Example #3
0
		public static void SetBindableText(TextBox element, string value)
		{
			if (element != null)
			{
				element.SetValue(BindableTextProperty, value);
			}
		}
Example #4
0
        public static void SetAlwaysScrollToEnd(TextBox textBox, bool alwaysScrollToEnd)
        {
            if (textBox == null)
                throw new ArgumentNullException(nameof(textBox));

            textBox.SetValue(AlwaysScrollToEndProperty, alwaysScrollToEnd);
        }
 private void addImage_Tapped(object sender, TappedRoutedEventArgs e)
 {
     numIngredients++;
     TextBox newTxtBox = new TextBox();
     newTxtBox.Name = "AIngredient" + numIngredients;
     newTxtBox.Margin = new Thickness(10, 0, 0, 0);
     newTxtBox.SetValue(Grid.RowProperty, addImage.GetValue(Grid.RowProperty));
     newTxtBox.SetValue(Grid.ColumnProperty, 0);
     IngredientsGrid.RowDefinitions.Add(new RowDefinition());
     addImage.SetValue(Grid.RowProperty, ((int)addImage.GetValue(Grid.RowProperty) + 1));
     IngredientsGrid.Children.Remove(addImage);
     IngredientsGrid.UpdateLayout();
     IngredientsGrid.Children.Add(newTxtBox);
     IngredientsGrid.UpdateLayout();
     IngredientsGrid.Children.Add(addImage);
     IngredientsGrid.UpdateLayout();
     IngredientsPanel.UpdateLayout();
 }
Example #6
0
 public static void SetIsAutoUpdate(TextBox obj, bool value)
 {
     obj.SetValue(IsAutoUpdateProperty, value);
 }
Example #7
0
 public static void SetRealTimeText(TextBox obj, string value)
 {
     obj.SetValue(RealTimeTextProperty, value);
 }
 public static void SetBindingSource(TextBox element, string value)
 {
     element.SetValue(BindingSourceProperty, value);
 }
Example #9
0
        private void _OnIsEditingChanged(bool isEditing, Item item)
        {
            UpdateGlyph();
            if (_leftSide != null) MainGrid.Children.Remove(_leftSide);

            if (isEditing)
            {
                TextBox box = new TextBox() {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center };
                box.SetValue(Grid.ColumnProperty, 0);
                box.FontSize = FontSize;
                box.SetBinding(TextBox.TextProperty, new Binding()
                {
                    Source = this,
                    Path = new PropertyPath(ItemMode ? "Item.Name" : "EditableText"),
                    Mode = BindingMode.TwoWay
                });
                
                _leftSide = box;
            }
            else
            {
                TextBlock block = new TextBlock() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Center };
                block.SetValue(Grid.ColumnProperty, 0);
                block.SetBinding(TextBlock.TextProperty, new Binding()
                {
                    Source = this,
                    Path = new PropertyPath(ItemMode ? "Item.Name" : "EditableText"),
                    Mode = BindingMode.OneWay
                });
                _leftSide = block;
            }

            MainGrid.Children.Add(_leftSide);
        }
        public async void LcdPrint(ScreenMessage lcdt)
        {
            var isText = lcdt.Service.Equals("LCDT");
            FrameworkElement element = null;
            var expandToEdge = false;
            SolidColorBrush backgroundBrush = null;

            if (lcdt.Action != null)
            {
                if (!string.IsNullOrWhiteSpace(lcdt.ARGB))
                {
                    if (lcdt.ARGB[0] == '#')
                    {
                        var hex = lcdt.ARGB.ToByteArray();
                        if (hex.Length > 3)
                        {
                            backgroundBrush =
                                new SolidColorBrush(Color.FromArgb((hex[0] == 0 ? (byte) 255 : hex[0]), hex[1], hex[2],
                                    hex[3]));
                        }
                    }
                    else
                    {
                        UInt32 color;
                        if (UInt32.TryParse(lcdt.ARGB, out color))
                        {
                            var argb = new ArgbUnion {Value = color};
                            backgroundBrush = new SolidColorBrush(Color.FromArgb(argb.A == 0 ? (byte) 255 : argb.A, argb.R, argb.G, argb.B));
                        }
                    }   
                }

                var action = lcdt.Action.ToUpperInvariant();
                switch (action)
                {
                    case "ORIENTATION":
                        {
                            var current = DisplayInformation.AutoRotationPreferences;
                            if (lcdt.Value.HasValue)
                            {
                                DisplayInformation.AutoRotationPreferences = (DisplayOrientations)lcdt.Value.Value;
                            }

                            await mainPage.SendResult(new ScreenResultMessage(lcdt) { ResultId = (int)current });

                            break;
                        }
                    case "ENABLE":
                        {
                            mainPage.sensors[lcdt.Service + ":" + lcdt.Message] = 1;
                            return;
                        }
                    case "DISABLE":
                        {
                            if (mainPage.sensors.ContainsKey(lcdt.Service + ":" + lcdt.Message))
                            {
                                mainPage.sensors.Remove(lcdt.Service + ":" + lcdt.Message);
                            }

                            return;
                        }
                    case "CLEAR":
                        {
                            if (lcdt.Y.HasValue)
                            {
                                RemoveLine(lcdt.Y.Value);
                            }
                            else if (lcdt.Pid.HasValue)
                            {
                                RemoveId(lcdt.Pid.Value);
                            }
                            else
                            {
                                mainPage.canvas.Children.Clear();

                                if (backgroundBrush != null)
                                {
                                    mainPage.canvas.Background = backgroundBrush;
                                }

                                lastY = -1;
                                mainPage.player.Stop();
                                mainPage.player.Source = null;
                            }

                            break;
                        }

                    case "BUTTON":
                        {
                            element = new Button
                            {
                                Content = lcdt.Message,
                                FontSize = lcdt.Size ?? DefaultFontSize,
                                Tag = lcdt.Tag,
                                Foreground = textForgroundBrush,
                                Background =  new SolidColorBrush(Colors.Gray)

                            };

                            element.Tapped += async (s, a) => await mainPage.SendEvent(s, a, "tapped");
                            ((Button)element).Click += async (s, a) => await mainPage.SendEvent(s, a, "click");
                            element.PointerPressed += async (s, a) => await mainPage.SendEvent(s, a, "pressed");
                            element.PointerReleased += async (s, a) => await mainPage.SendEvent(s, a, "released");

                            break;
                        }

                    case "IMAGE":
                        {
                            var imageBitmap = new BitmapImage(new Uri(lcdt.Path, UriKind.Absolute));
                            //imageBitmap.CreateOptions = Windows.UI.Xaml.Media.Imaging.BitmapCreateOptions.IgnoreImageCache;

                            if (lcdt.Width.HasValue)
                            {
                                imageBitmap.DecodePixelWidth = lcdt.Width.Value;
                            }

                            if (lcdt.Height.HasValue)
                            {
                                imageBitmap.DecodePixelHeight = lcdt.Height.Value;
                            }

                            element = new Image
                            {
                                Tag = lcdt.Tag
                            };

                            ((Image)element).Source = imageBitmap;

                            element.Tapped += async (s, a) => await mainPage.SendEvent(s, a, "tapped");
                            break;
                        }
                    case "LINE":
                    {
                        var line = new Line
                        {
                            X1 = lcdt.X.Value,
                            Y1 = lcdt.Y.Value,
                            X2 = lcdt.X2.Value,
                            Y2 = lcdt.Y2.Value,
                            StrokeThickness = lcdt.Width ?? 1,
                            Stroke = foreground
                        };

                        element = line;

                        break;
                    }

                    case "INPUT":
                        {
                            element = new TextBox
                            {
                                Text = lcdt.Message,
                                FontSize = lcdt.Size ?? DefaultFontSize,
                                TextWrapping = TextWrapping.Wrap,
                                Foreground = textForgroundBrush,
                                AcceptsReturn = lcdt.Multi ?? false
                            };

                            expandToEdge = true;

                            element.SetValue(Canvas.LeftProperty, lcdt.X);
                            element.SetValue(Canvas.TopProperty, lcdt.Y);

                            element.LostFocus += async (s, a) => await mainPage.SendEvent(s, a, "lostfocus", lcdt, ((TextBox)s).Text);
                            ((TextBox)element).TextChanged += async (s, a) => await mainPage.SendEvent(s, a, "changed", lcdt, ((TextBox)s).Text);

                            break;
                        }
                    case "CHANGE":
                        {
                            var retrievedElement = GetId(lcdt.Pid.Value);
                            if (retrievedElement != null)
                            {
                                if (lcdt.ARGB != null)
                                {
                                    var i = 0;
                                }
                            }

                            break;
                        }
                    case "RECTANGLE":
                        {
                            var rect = new Rectangle
                            {
                                Tag = lcdt.Tag,
                                Fill = backgroundBrush ?? gray
                            };

                            if (lcdt.Width.HasValue)
                            {
                                rect.Width = lcdt.Width.Value;
                            }

                            if (lcdt.Height.HasValue)
                            {
                                rect.Height = lcdt.Height.Value;
                            }

                            element = rect;

                            element.Tapped += async (s, a) => await mainPage.SendEvent(s, a, "tapped", lcdt);
                            rect.PointerEntered += async (s, a) => await mainPage.SendEvent(s, a, "entered", lcdt);
                            rect.PointerExited += async (s, a) => await mainPage.SendEvent(s, a, "exited", lcdt);

                            break;
                        }
                    case "TEXT":
                        {
                            TextBlock textBlock = new TextBlock
                            {
                                Text = lcdt.Message,
                                FontSize = lcdt.Size ?? DefaultFontSize,
                                TextWrapping = TextWrapping.Wrap,
                                Tag = lcdt.Tag,
                                Foreground = textForgroundBrush
                            };

                            expandToEdge = true;

                            element = textBlock;
                            element.SetValue(Canvas.LeftProperty, lcdt.X);
                            element.SetValue(Canvas.TopProperty, lcdt.Y);
                            break;
                        }

                    default:
                        break;
                }
            }

            if (element == null && isText && lcdt.Message != null)
            {
                var x = lcdt.X ?? 0;
                var y = lcdt.Y ?? lastY + 1;

                expandToEdge = true;

                element = new TextBlock
                {
                    Text = lcdt.Message,
                    FontSize = lcdt.Size ?? DefaultFontSize,
                    TextWrapping = TextWrapping.Wrap,
                    Tag = y.ToString(),
                    Foreground = textForgroundBrush
                };

                var textblock = (TextBlock)element;

                textblock.FontFamily = fixedFont;

                if (lcdt.Foreground != null)
                {
                    textblock.Foreground = HexColorToBrush(lcdt.Foreground);
                }

                if (lcdt.HorizontalAlignment != null)
                {
                    if (lcdt.HorizontalAlignment.Equals("Center"))
                    {
                        textblock.TextAlignment = TextAlignment.Center;
                    }
                }

                element.SetValue(Canvas.LeftProperty, isText ? x * textblock.FontSize : x);
                element.SetValue(Canvas.TopProperty, isText ? y * textblock.FontSize : y);
            }
            else if (element != null && element.GetType() != typeof(Line))
            {
                element.SetValue(Canvas.LeftProperty, lcdt.X);
                element.SetValue(Canvas.TopProperty, lcdt.Y);
            }

            if (element != null)
            {
                var x = lcdt.X ?? 0;
                var y = lcdt.Y ?? lastY + 1;

                if (lcdt.HorizontalAlignment != null)
                {
                    if (lcdt.HorizontalAlignment.Equals("Center"))
                    {
                        element.HorizontalAlignment = HorizontalAlignment.Center;
                        element.Width = mainPage.canvas.Width;
                    }
                }

                if (lcdt.FlowDirection != null)
                {
                    if (lcdt.FlowDirection.Equals("RightToLeft"))
                    {
                        element.FlowDirection = FlowDirection.RightToLeft;
                    } else if (lcdt.FlowDirection.Equals("LeftToRight"))
                    {
                        element.FlowDirection = FlowDirection.LeftToRight;
                    }
                }

                if (lcdt.Width.HasValue)
                {
                    element.Width = lcdt.Width.Value;
                }
                else if (expandToEdge)
                {
                    element.Width = mainPage.canvas.ActualWidth;
                }

                if (lcdt.Height.HasValue)
                {
                    element.Height = lcdt.Height.Value;
                }

                //TODO: add optional/extra properties in a later version here.
                if (isText && x == 0)
                {
                    RemoveLine(y);
                }

                element.SetValue(RemoteIdProperty, lcdt.Id);

                mainPage.canvas.Children.Add(element);

                if (isText)
                {
                    lastY = y;
                }
            }
        }