Beispiel #1
0
        private void SetProgress()
        {
            if (this.Progress != null)
            {
                return;
            }

            bool available = false;

            lock (_progressCountLock)
            {
                if (_progressCount < 100)
                {
                    _progressCount++;
                    available = true;
                }
            }

            if (available)
            {
                var progress = new ProgressRing
                {
                    IsActive = true
                };
                progress.SetBinding(ProgressRing.BackgroundProperty, new Binding {
                    Source = this, Path = new PropertyPath("Background")
                });
                progress.SetBinding(ProgressRing.ForegroundProperty, new Binding {
                    Source = this, Path = new PropertyPath("Foreground")
                });
                this.Content = progress;
            }
        }
Beispiel #2
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;
        }
Beispiel #3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //string html = GetYoutubeIframeHtml("Bvojzrq9Ad4", myWebView.ActualWidth, myWebView.ActualHeight, true);
            //string html = "https://forum.gamer.com.tw/A.php?bsn=60030";
            //myWebView.NavigateToString(GGG());

            //MyPanel.Children.Clear();
            //https://stackoverflow.com/questions/1602148/binding-to-actualwidth-does-not-work
            Grid MainGrid = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch, Background = new SolidColorBrush(Colors.Gray)
            };

            ColumnDefinition c1, c2, c3;

            double space = 0.2; //也就是佔總寬的80%

            c1 = new ColumnDefinition {
                Width = new GridLength(space / 2.0, GridUnitType.Star)
            };
            c2 = new ColumnDefinition {
                Width = new GridLength((1 - space), GridUnitType.Star)
            };
            c3 = new ColumnDefinition {
                Width = new GridLength(space / 2.0, GridUnitType.Star)
            };

            MainGrid.ColumnDefinitions.Add(c1);
            MainGrid.ColumnDefinitions.Add(c2);
            MainGrid.ColumnDefinitions.Add(c3);

            Grid InnerGrid = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch, Background = new SolidColorBrush(Colors.Black)
            };

            InnerGrid.SetValue(Grid.ColumnProperty, 1);
            MainGrid.Children.Add(InnerGrid);

            Grid youtuGrid = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch
            };

            youtuGrid.SetBinding(HeightProperty, new Binding {
                ElementName = "proxy", Path = new PropertyPath("ActualWidthValue"), Converter = Application.Current.Resources["MyRatioConverter"] as RatioConverter
            });
            InnerGrid.Children.Add(youtuGrid);

            MyGrid.Children.Add(MainGrid);

            /***
             * Grid grid = new Grid() { HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch,};
             *
             * Binding bind = new Binding()
             * {
             *  RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.TemplatedParent },
             *  Path = new PropertyPath("ActualWidth"),
             *  Mode = BindingMode.OneWay,
             * };
             *
             * grid.SetBinding(HeightProperty, bind);
             *
             *
             *
             *
             * grid.Children.Add(wwvv);
             * /***/
            //MyPanel.Children.Add(grid);
            ActualSizePropertyProxy po = MyGrid.Resources["proxy"] as ActualSizePropertyProxy;


            ProgressRing ring = new ProgressRing()
            {
                IsActive = true, Foreground = new SolidColorBrush(Colors.Orange)
            };
            Binding ringBinding = new Binding {
                ElementName = "proxy", Path = new PropertyPath("ActualWidthValue"), Converter = Application.Current.Resources["MyRingRatioConverter"] as RingRatioConverter
            };

            ring.SetBinding(WidthProperty, ringBinding);
            ring.SetBinding(HeightProperty, ringBinding);
            wwvv = new WebView()
            {
                DefaultBackgroundColor = Colors.Gray
            };


            wwvv.ContentLoading += (a, b) =>
            {
                wwvv.Visibility = Visibility.Collapsed;
            };

            wwvv.FrameDOMContentLoaded += (a, b) =>
            {
                ring.IsActive   = false;
                wwvv.Visibility = Visibility.Visible;
            };

            wwvv.DOMContentLoaded += async(a, b) =>
            {
                try
                {
                    string returnStr = await wwvv.InvokeScriptAsync("LoadYoutube", new string[] { "oXp2oE0xQcE" });
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Script Error" + ex.ToString());
                }
            };

            youtuGrid.Children.Add(wwvv);
            youtuGrid.Children.Add(ring);

            wwvv.Navigate(new Uri("ms-appx-web:///Templates/youtube/youtube.html"));
        }
Beispiel #4
0
        void OnLoaded(object sender, RoutedEventArgs e)
        {
            var model = DataContext as IViewModelCore;

            if (model != null)
            {
                Grid root = null;
                if (Content is Grid)
                {
                    root = (Grid)Content;
                }
                else if (Content is Border)
                {
                    var child = (Content as Border).Child as Grid;
                    if (child != null)
                    {
                        root = child;
                    }
                }
                if (root != null)
                {
                    var curtainGrid = new Grid();
                    curtainGrid.SetValue(Canvas.ZIndexProperty, 9999);
                    curtainGrid.Opacity = 0.6;

                    var brush = new LinearGradientBrush {
                        EndPoint = new Point(0.5, 1), StartPoint = new Point(0.5, 0)
                    };
                    var stops = new GradientStopCollection();

                    var stop = new GradientStop {
                        Color = new Color {
                            R = 0x80, G = 0x74, B = 0xD4
                        }
                    };
                    stops.Add(stop);

                    stop = new GradientStop {
                        Color = new Color {
                            R = 0x80, G = 0x74, B = 0xD4
                        }, Offset = 1
                    };
                    stops.Add(stop);

                    stop = new GradientStop {
                        Color = new Color {
                            R = 0xB7, G = 0x84, B = 0xD0
                        }, Offset = 0.5
                    };
                    stops.Add(stop);
                    brush.GradientStops = stops;

                    curtainGrid.Background = brush;

                    var progressRign = new ProgressRing {
                        MinHeight = 100, MinWidth = 100, TabNavigation = KeyboardNavigationMode.Cycle
                    };
                    var binding = new Binding {
                        Path = new PropertyPath(IsBusy)
                    };
                    progressRign.HorizontalAlignment = HorizontalAlignment.Center;
                    progressRign.VerticalAlignment   = VerticalAlignment.Center;
                    progressRign.SetBinding(ProgressRing.IsActiveProperty, binding);
                    curtainGrid.Children.Add(progressRign);

                    binding = new Binding {
                        Path = new PropertyPath(IsBusy), Converter = new BooleanToVisibilityConverter()
                    };
                    curtainGrid.SetBinding(VisibilityProperty, binding);

                    root.Children.Add(curtainGrid);
                    if (root.ColumnDefinitions != null && root.ColumnDefinitions.Count > 1)
                    {
                        curtainGrid.SetValue(Grid.ColumnSpanProperty, root.ColumnDefinitions.Count);
                    }
                    if (root.RowDefinitions != null && root.RowDefinitions.Count > 1)
                    {
                        curtainGrid.SetValue(Grid.RowSpanProperty, root.RowDefinitions.Count);
                    }
                    if (model.IsBusy)
                    {
                        Dispatcher.RunAsync(CoreDispatcherPriority.Low, () => progressRign.Focus(FocusState.Programmatic));
                    }

                    model.PropertyChanged += (o1, e1) =>
                    {
                        if (e1.PropertyName == IsBusy)
                        {
                            if (model.IsBusy)
                            {
                                this.IsHitTestVisible = false;
                                progressRign.Focus(FocusState.Programmatic);
                            }
                            else
                            {
                                Focus(FocusState.Programmatic);
                                this.IsHitTestVisible = true;
                            }
                            Messenger.Default.Send <IViewModelCore>((IViewModelCore)DataContext, "RefreshAppBar");
                        }
                    };

                    Loaded -= OnLoaded;
                }
            }
        }
Beispiel #5
0
        private UIElement LocationUIEl()
        {
            StackPanel sp = new StackPanel()
            {
                Orientation = Orientation.Horizontal,
            };
            StackPanel innersp = new StackPanel()
            {
                Orientation = Orientation.Vertical,
            };
            TextBox t = new TextBox()
            {
                DataContext = this,
                Margin      = new Thickness(0, 0, 0, 4),
                MinWidth    = 200,
            };
            Binding bind = new Binding()
            {
                Path = new PropertyPath("Location"),
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger   = UpdateSourceTrigger.PropertyChanged,
                ValidatesOnDataErrors = true,
            };

            t.SetBinding(TextBox.TextProperty, bind);
            t.InputBindings.Add(new InputBinding(new RelayCommand(o => { ValidateLocations(location); }), new KeyGesture(Key.Enter)));

            Button directions = new Button()
            {
                Margin    = new Thickness(0, 0, 0, 4),
                Content   = "Press Enter key to validate locations",
                Style     = Application.Current.Resources["SystemButtonLink"] as Style,
                IsEnabled = false,
            };

            innersp.Children.Add(t);
            innersp.Children.Add(directions);

            TextBlock checkMark = new TextBlock()
            {
                Text        = "✔",
                DataContext = this,
                Foreground  = System.Windows.Media.Brushes.Green,
                FontSize    = 16,
                FontWeight  = FontWeights.ExtraBold,
                Margin      = new Thickness(10, 0, 0, 4),
            };
            Binding bind2 = new Binding("LocationsSaved")
            {
                Converter = Application.Current.Resources["BooleanToVisibilityConverter"] as IValueConverter
            };

            checkMark.SetBinding(TextBlock.VisibilityProperty, bind2);

            ProgressRing loadingRing = new ProgressRing()
            {
                DataContext       = this,
                Height            = 18, Width = 18, Margin = new Thickness(10, 3, 0, 4),
                State             = ProgressState.Indeterminate,
                VerticalAlignment = VerticalAlignment.Top,
            };

            loadingRing.SetResourceReference(ProgressRing.ForegroundProperty, "Accent");
            Binding bind3 = new Binding("IsValidatingLocations")
            {
                Converter = Application.Current.Resources["BooleanToVisibilityConverter"] as IValueConverter
            };

            loadingRing.SetBinding(ProgressRing.VisibilityProperty, bind3);

            sp.Children.Add(innersp);
            sp.Children.Add(checkMark);
            sp.Children.Add(loadingRing);
            return(sp);
        }