Exemple #1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _textBox         = GetTemplateChild("TextBox") as TextBox;
            _popup           = GetTemplateChild("SuggestionsPopup") as Popup;
            _layoutRoot      = GetTemplateChild("LayoutRoot") as Grid;
            _suggestionsList = GetTemplateChild("SuggestionsList") as ListView;
            _queryButton     = GetTemplateChild("QueryButton") as Button;

            if (_queryButton != null)
            {
                _queryButton.Content = new SymbolIcon(Symbol.Find);
            }

            _textBox?.SetBinding(
                TextBox.TextProperty,
                new Binding()
            {
                Path                = "Text",
                RelativeSource      = RelativeSource.TemplatedParent,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Mode                = BindingMode.TwoWay
            }
                );

            Loaded   += (s, e) => RegisterEvents();
            Unloaded += (s, e) => UnregisterEvents();

            if (IsLoaded)
            {
                RegisterEvents();
            }
        }
Exemple #2
0
        private UWPControls.StackPanel CreateInputStackPanel()
        {
            var inputStackPanel = new UWPControls.StackPanel();

            UWPControls.Button getTokenButton = new UWPControls.Button();
            getTokenButton.Content             = "Lấy Facebook Token";
            getTokenButton.Width               = 300;
            getTokenButton.HorizontalAlignment = UWPXaml.HorizontalAlignment.Center;
            getTokenButton.Margin              = new UWPXaml.Thickness(10);
            getTokenButton.SetBinding(UWPControls.Button.CommandProperty, new UWPXaml.Data.Binding()
            {
                Source = _viewModel,
                Path   = new UWPXaml.PropertyPath("GetTokenCommand")
            });

            UWPControls.PasswordBox passwordBox = new UWPControls.PasswordBox();
            passwordBox.PlaceholderText  = "Nhập password";
            passwordBox.Width            = 300;
            passwordBox.Margin           = new UWPXaml.Thickness(10);
            passwordBox.PasswordChanged += (o, args) => { _viewModel.UserPassword = passwordBox.Password; };

            //Thêm tooltip cho password TextBox
            UWPControls.ToolTip passwordToolTip = new UWPControls.ToolTip();
            passwordToolTip.Content =
                "Để giảm thiểu khả năng checkpoint và tăng độ bảo mật, các bạn nên dùng Mật khẩu ứng dụng. Để lấy Mật khẩu ứng dụng: Cài đặt > Bảo mật và đăng nhập > Xác thực 2 yếu tố > Mật khẩu ứng dụng";
            UWPControls.ToolTipService.SetToolTip(passwordBox, passwordToolTip);

            UWPControls.TextBox emailTextBox = new UWPControls.TextBox();
            emailTextBox.PlaceholderText     = "Nhập email";
            emailTextBox.IsSpellCheckEnabled = false;
            emailTextBox.Width  = 300;
            emailTextBox.Margin = new UWPXaml.Thickness(10);
            //https://github.com/Microsoft/XamlIslandBlogPostSample/blob/master/WpfApp1/BindingPage.xaml.cs
            emailTextBox.SetBinding(UWPControls.TextBox.TextProperty, new UWPXaml.Data.Binding()
            {
                Source = _viewModel,
                Path   = new UWPXaml.PropertyPath("UserEmail"),
                UpdateSourceTrigger = UWPXaml.Data.UpdateSourceTrigger.PropertyChanged,
                Mode = UWPXaml.Data.BindingMode.TwoWay
            });


            inputStackPanel.Children.Add(emailTextBox);
            inputStackPanel.Children.Add(passwordBox);
            inputStackPanel.Children.Add(getTokenButton);

            return(inputStackPanel);
        }
        /// <summary>
        /// Creates a textbox to allow input of custom values for custom type RadialMenuButtons
        /// </summary>
        private void CreateCustomTextBox()
        {
            CustomTextBox = new TextBox
            {
                Name = "CustomTextBox",
                FontSize = LabelSize,
                Margin = new Thickness(0, 67, 0, 0),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Center,
                BorderThickness = new Thickness(0),
                TextAlignment = TextAlignment.Center,
                Background = new SolidColorBrush(Colors.Transparent),
                AcceptsReturn = false,
                Style = (Style)this.Resources["TransparentTextBox"]
            };

            CustomTextBox.Padding = new Thickness(0);

            CustomTextBox.GotFocus += (sender, args) => LabelTextElement.Opacity = 0;
            CustomTextBox.LostFocus += (sender, args) =>
            {
                OriginalRadialMenuButton.Value = ((TextBox)sender).Text;
                LabelTextElement.Opacity = 1;
                OriginalRadialMenuButton.OnValueChanged(args);

            };
            CustomTextBox.SetBinding(TextBox.TextProperty, new Windows.UI.Xaml.Data.Binding() { Source = this.CustomValue });

            TextLabelGrid.Children.Add(CustomTextBox);
        }
Exemple #4
0
        private void ComboBox_SelectionChanged(object sender,
            SelectionChangedEventArgs e)
        {
            Service currentService
                = ServicesComboBox.SelectedItem as Service;

            metricDetails.Children.Clear();

            foreach (string item in currentService.Properties.Keys)
            {
                var textBlock = new TextBlock();
                textBlock.Text = item;
                textBlock.Style = App.Current.Resources["TitleTextStyle"] as Style;
                textBlock.Margin = new Thickness(0, 16, 0, 0);
                metricDetails.Children.Add(textBlock);

                var textBox = new TextBox();
                textBox.Foreground = new SolidColorBrush(Colors.Black);
                textBox.Margin = new Thickness(0, 8, 0, 0);

                Binding binding = new Binding();
                binding.Path = new PropertyPath("Content");
                binding.Source = currentService.Properties[item];
                binding.Mode = BindingMode.TwoWay;
                textBox.SetBinding(TextBox.TextProperty, binding);
                metricDetails.Children.Add(textBox);
            }
        }
Exemple #5
0
        private UWPControls.StackPanel CreateResultStackPanel()
        {
            var resultStackPanel = new UWPControls.StackPanel();

            //Dùng cho hiển thị Token

            UWPControls.TextBox fbTokenTextBox = new UWPControls.TextBox();
            fbTokenTextBox.Width           = 300;
            fbTokenTextBox.Margin          = new UWPXaml.Thickness(10);
            fbTokenTextBox.BorderThickness = new UWPXaml.Thickness(0);
            fbTokenTextBox.Background      = new UWPXaml.Media.SolidColorBrush(Windows.UI.Colors.Transparent);
            fbTokenTextBox.IsReadOnly      = true;
            fbTokenTextBox.TextWrapping    = UWPXaml.TextWrapping.Wrap;
            fbTokenTextBox.SetBinding(UWPControls.TextBox.TextProperty, new UWPXaml.Data.Binding()
            {
                Source = _viewModel,
                Path   = new UWPXaml.PropertyPath("FBToken"),
                Mode   = UWPXaml.Data.BindingMode.OneWay
            });

            UWPControls.Button copyTokenButton = new UWPControls.Button();
            copyTokenButton.Width   = 150;
            copyTokenButton.Margin  = new UWPXaml.Thickness(0, 0, 5, 0);
            copyTokenButton.Content = "Sao chép Token";
            copyTokenButton.Click  += (o, args) => { Clipboard.SetText(_viewModel.FBToken ?? string.Empty); };

            UWPControls.Button saveTokenButton = new UWPControls.Button {
                Width = 120, Content = "Lưu Token"
            };
            saveTokenButton.SetBinding(UWPControls.Button.CommandProperty, new UWPXaml.Data.Binding()
            {
                Source = _viewModel,
                Path   = new UWPXaml.PropertyPath("SaveTokenCommand")
            });

            UWPControls.StackPanel successCommandButtonsStackPanel = new UWPControls.StackPanel();
            successCommandButtonsStackPanel.Orientation         = UWPControls.Orientation.Horizontal;
            successCommandButtonsStackPanel.Margin              = new UWPXaml.Thickness(10);
            successCommandButtonsStackPanel.HorizontalAlignment = UWPXaml.HorizontalAlignment.Center;
            successCommandButtonsStackPanel.Children.Add(copyTokenButton);
            successCommandButtonsStackPanel.Children.Add(saveTokenButton);


            UWPControls.StackPanel successStackPanel = new UWPControls.StackPanel();

            successStackPanel.Children.Add(fbTokenTextBox);
            successStackPanel.Children.Add(successCommandButtonsStackPanel);

            successStackPanel.SetBinding(UWPXaml.UIElement.VisibilityProperty,
                                         new UWPXaml.Data.Binding()
            {
                Source    = _viewModel,
                Path      = new UWPXaml.PropertyPath("FBToken"),
                Converter = new NullTovisibilityConverter()
            });

            //Dùng cho hiển thị lỗi
            UWPControls.StackPanel errorStackPanel = new UWPControls.StackPanel();

            UWPControls.TextBlock errorMsgTextBlock = new UWPControls.TextBlock();
            errorMsgTextBlock.Width        = 300;
            errorMsgTextBlock.TextWrapping = UWPXaml.TextWrapping.WrapWholeWords;
            errorMsgTextBlock.Foreground   = new UWPXaml.Media.SolidColorBrush(Windows.UI.Colors.Red);
            errorMsgTextBlock.SetBinding(UWPControls.TextBlock.TextProperty, new UWPXaml.Data.Binding()
            {
                Source = _viewModel,
                Path   = new UWPXaml.PropertyPath("ErrorMsg")
            });

            errorStackPanel.Children.Add(errorMsgTextBlock);

            //Thêm cả 2 panel success và error vào panel chính
            resultStackPanel.Children.Add(errorStackPanel);
            resultStackPanel.Children.Add(successStackPanel);

            return(resultStackPanel);
        }
Exemple #6
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);
        }
Exemple #7
0
        private void BuildControl(InputType type, string label, string placeholderText, double labelFontSize, double labelTranslateY, string groupName, ContentControl ccInput) {

            FrameworkElement fe = null;

            if (type == InputType.text)
            {
                _udfTB1 = new TextBox();
                _udfTB1.PlaceholderText = placeholderText;
                _udfTB1.Style = _GeneralTextBoxStyle;
                _udfTB1.SetBinding(TextBox.DataContextProperty, new Binding() { Path= new PropertyPath("{x:Null}") });
                _udfTB1.SetBinding(TextBox.TextProperty, new Binding() { Source = Value });
                _udfTB1.KeyUp += ittext_KeyUp;

                _udfg1 = new Grid() { Padding = new Thickness(2, 2, 2, 2), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment= VerticalAlignment.Top};
                _udfTBL1 = new TextBlock();
                _udfTBL1.Text = label;
                _udfTBL1.FontSize = labelFontSize;
                _udfg1.Margin = new Thickness(0, labelTranslateY, 0, 0);
                _udfg1.Visibility = Visibility.Collapsed;
                _udfg1.Children.Add(_udfTBL1);
                
                var gd = new Grid();
                gd.Children.Add(_udfg1);
                gd.Children.Add(_udfTB1);

                fe = gd;
            }
            else if (type == InputType.password)
            {
                _udfPB1 = new PasswordBox();
                _udfPB1.PlaceholderText = placeholderText;
                _udfPB1.Style = _GeneralPasswordBoxStyle;
                _udfPB1.PasswordChanged += itpassword_PasswordChanged;

                _udfg1 = new Grid() { Padding = new Thickness(2, 2, 2, 2), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top };
                _udfTBL1 = new TextBlock();
                _udfTBL1.Text = label;
                _udfTBL1.FontSize = labelFontSize;
                _udfg1.Margin = new Thickness(0, labelTranslateY, 0, 0);
                _udfg1.Visibility = Visibility.Collapsed;
                _udfg1.Children.Add(_udfTBL1);

                var gd = new Grid();
                gd.Children.Add(_udfg1);
                gd.Children.Add(_udfPB1);

                fe = gd;
            }
            else if (type == InputType.combobox)
            {
                _udfCB1 = new ComboBox();
                _udfCB1.Style = _GeneralComboBoxStyle;
                _udfCB1.PlaceholderText = placeholderText;
                _udfCB1.SetBinding(ComboBox.ItemsSourceProperty, new Binding() { Source = Items });
                _udfCB1.Width = this.Width;
                _udfCB1.SelectionChanged += itcombobox_SelectionChanged;

                _udfg1 = new Grid() { Padding = new Thickness(2, 2, 2, 2), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top };
                _udfTBL1 = new TextBlock();
                _udfTBL1.Text = label;
                _udfTBL1.FontSize = labelFontSize;
                _udfg1.Margin = new Thickness(0, labelTranslateY, 0, 0);
                _udfg1.Visibility = Visibility.Collapsed;
                _udfg1.Children.Add(_udfTBL1);

                var gd = new Grid();
                gd.Children.Add(_udfg1);
                gd.Children.Add(_udfCB1);

                fe = gd;
            }
            else if (type == InputType.checkbox)
            {
                var sp = new StackPanel();
                sp.Orientation = Orientation.Horizontal;
                
                var lb = new TextBlock();
                lb.Text = label;
                lb.FontSize = LabelFontSize;
                lb.Margin = new Thickness(0, LabelTranslateY, 0, 0);

                _udfChkB1 = new CheckBox();
                _udfChkB1.Checked += itcheckbox_Changed;
                _udfChkB1.Unchecked += itcheckbox_Changed;
                _udfChkB1.Content = lb;
                _udfChkB1.Style = _GeneralCheckBoxStyle;
                sp.Children.Add(_udfChkB1);

                fe = sp;
            }
            else if (type == InputType.toggleButton)
            {
                _udfTBut1 = new ToggleButton();
                _udfTBut1.Style = _GeneralToggleButtonStyle;
                _udfTBut1.Checked += ittogglebutton_changed;
                _udfTBut1.Unchecked += ittogglebutton_changed;
                _udfTBut1.FontSize = FontSize;
                _udfTBut1.Content = Content1;
                fe = _udfTBut1;
            }
            else if (type == InputType.toggleSwitch)
            {
                _udfTS1 = new ToggleSwitch();
                _udfTS1.Style = _GeneralToggleSwitchStyle;
                _udfTS1.Toggled += ittoggleswitch_Toggled;
                _udfTS1.FontSize = FontSize;
                _udfTS1.OnContent = Content1;
                _udfTS1.OffContent = Content2;
                fe = _udfTS1;
            }
            else if (type == InputType.radio)
            {
                var sp = new StackPanel();
                sp.Orientation = Orientation.Horizontal;
                
                var lb = new TextBlock();
                lb.Text = label;
                lb.FontSize = LabelFontSize;
                lb.Margin = new Thickness(0, LabelTranslateY, 0, 0);

                _udfRB1 = new RadioButton();
                _udfRB1.GroupName = groupName;
                _udfRB1.Checked += itradio_Changed;
                _udfRB1.Unchecked += itradio_Changed;
                _udfRB1.Content = lb;
                _udfRB1.Style = _GeneralRadioButtonStyle;
                sp.Children.Add(_udfRB1);

                fe = sp;
            }
            else if (type == InputType.progress)
            {
                _udfProgBr1 = new ProgressBar();
                _udfProgBr1.Style = _GeneralProgressBarStyle;
                _udfProgBr1.ValueChanged += itProgBr_ValueChanged;
                _udfProgBr1.FontSize = FontSize;
                _udfProgBr1.DataContext = this;
                _udfProgBr1.SetBinding(ProgressBar.MaximumProperty, new Binding() { Path= new PropertyPath("Maximum1") });
                _udfProgBr1.SetBinding(ProgressBar.MinimumProperty, new Binding() { Path = new PropertyPath("Minimum1") });
                _udfProgBr1.SetBinding(ProgressBar.ValueProperty, new Binding() { Path = new PropertyPath("Value1")  });
                _udfProgBr1.SetBinding(ProgressBar.SmallChangeProperty, new Binding() { Path = new PropertyPath("SmallChange1") });
                _udfProgBr1.SetBinding(ProgressBar.LargeChangeProperty, new Binding() { Path = new PropertyPath("LargeChange1") });
                
                fe = _udfProgBr1;
            }
            else if (type == InputType.progressRing)
            {
                _udfProgRn1 = new ProgressRing();
                _udfProgRn1.Style = _GeneralProgressRingStyle;
                //_udfProgRn1.val += itProgBr_ValueChanged;
                _udfProgRn1.FontSize = FontSize;
                _udfProgRn1.DataContext = this;
                _udfProgRn1.SetBinding(ProgressRing.IsActiveProperty, new Binding() { Path = new PropertyPath("IsActive") });

                fe = _udfProgRn1;
            }
            else if (type == InputType.slider)
            {
                _udfSl1 = new Slider();
                _udfSl1.Style = _GeneralSliderStyle;
                _udfSl1.ValueChanged += itSl_ValueChanged;
                _udfSl1.FontSize = FontSize;
                _udfSl1.DataContext = this;
                _udfSl1.SetBinding(Slider.MaximumProperty, new Binding() { Path = new PropertyPath("Maximum1") });
                _udfSl1.SetBinding(Slider.MinimumProperty, new Binding() { Path = new PropertyPath("Minimum1") });
                _udfSl1.SetBinding(Slider.ValueProperty, new Binding() { Path = new PropertyPath("Value1") });
                _udfSl1.SetBinding(Slider.SmallChangeProperty, new Binding() { Path = new PropertyPath("SmallChange1") });
                _udfSl1.SetBinding(Slider.StepFrequencyProperty, new Binding() { Path = new PropertyPath("SmallChange1") });
                _udfSl1.SetBinding(Slider.LargeChangeProperty, new Binding() { Path = new PropertyPath("LargeChange1") });

                fe = _udfSl1;
            }



            fe.HorizontalAlignment = HorizontalAlignment.Stretch;
            fe.VerticalAlignment = VerticalAlignment.Stretch;
            ccInput.Content = fe;

        }