Пример #1
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _tb = GetTemplateChild("tabButton") as Button;
            

            _tb.Click += _tb_Click;

            var p1 = GetTabListParent(_tb);
            _tb.SetBinding(BorderBrushProperty, new Binding() { Path = new PropertyPath("TabItemBorderColor"), Source = p1 });  
            //_tb.BorderBrush = p1.TabItemBorderColor;
            
        }
Пример #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);
        }
Пример #3
0
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            UnbindMediaPlayer();

            var trueToVisible = new FromNullableBoolToVisibilityConverter();

            _playPauseButton = this.GetTemplateChild(PlayPauseButtonName) as Button;

            _playPauseButtonOnLeft = this.GetTemplateChild(PlayPauseButtonOnLeftName) as Button;

            _volumeMuteButton = this.GetTemplateChild(VolumeMuteButtonName) as Button;
            _volumeMuteButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsVolumeButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });
            _volumeMuteButton?.SetBinding(Button.IsEnabledProperty, new Binding {
                Path = "IsVolumeEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
            });

            _audioMuteButton = this.GetTemplateChild(AudioMuteButtonName) as Button;

            _volumeSlider = this.GetTemplateChild(VolumeSliderName) as Slider;
            if (_volumeSlider != null)
            {
                _volumeSlider.Maximum = 100;
                _volumeSlider.Value   = 100;
            }

            _fullWindowButton = this.GetTemplateChild(FullWindowButtonName) as Button;
            if (_fullWindowButton != null)
            {
                _fullWindowButton.SetBinding(Button.VisibilityProperty, new Binding {
                    Path = "IsFullWindowButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
                });
                _fullWindowButton.SetBinding(Button.IsEnabledProperty, new Binding {
                    Path = "IsFullWindowEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
                });
                _fullWindowButton.Tapped -= FullWindowButtonTapped;
                _fullWindowButton.Tapped += FullWindowButtonTapped;
            }

            _castButton = this.GetTemplateChild(CastButtonName) as Button;

            _zoomButton = this.GetTemplateChild(ZoomButtonName) as Button;

            if (_zoomButton != null)
            {
                _zoomButton?.SetBinding(Button.VisibilityProperty, new Binding {
                    Path = "IsZoomButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
                });
                _zoomButton?.SetBinding(Button.IsEnabledProperty, new Binding {
                    Path = "IsZoomEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
                });
                _zoomButton.Tapped -= ZoomButtonTapped;
                _zoomButton.Tapped += ZoomButtonTapped;
            }

            _playbackRateButton = this.GetTemplateChild(PlaybackRateButtonName) as Button;
            _playbackRateButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsPlaybackRateButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });
            _playbackRateButton?.SetBinding(Button.IsEnabledProperty, new Binding {
                Path = "IsPlaybackRateEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
            });

            _skipForwardButton = this.GetTemplateChild(SkipForwardButtonName) as Button;
            _skipForwardButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsSkipForwardButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });
            _skipForwardButton?.SetBinding(Button.IsEnabledProperty, new Binding {
                Path = "IsSkipForwardEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
            });

            _nextTrackButton = this.GetTemplateChild(NextTrackButtonName) as Button;
            _nextTrackButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsNextTrackButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });

            _fastForwardButton = this.GetTemplateChild(FastForwardButtonName) as Button;
            _fastForwardButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsFastForwardButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });
            _fastForwardButton?.SetBinding(Button.IsEnabledProperty, new Binding {
                Path = "IsFastForwardEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
            });

            _rewindButton = this.GetTemplateChild(RewindButtonName) as Button;
            _rewindButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsFastRewindButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });
            _rewindButton?.SetBinding(Button.IsEnabledProperty, new Binding {
                Path = "IsFastRewindEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
            });

            _previousTrackButton = this.GetTemplateChild(PreviousTrackButtonName) as Button;
            _previousTrackButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsPreviousTrackButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });

            _skipBackwardButton = this.GetTemplateChild(SkipBackwardButtonName) as Button;
            _skipBackwardButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsSkipBackwardButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });
            _skipBackwardButton?.SetBinding(Button.IsEnabledProperty, new Binding {
                Path = "IsSkipBackwardEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
            });

            _stopButton = this.GetTemplateChild(StopButtonName) as Button;
            _stopButton?.SetBinding(Button.VisibilityProperty, new Binding {
                Path = "IsStopButtonVisible", Source = this, Mode = BindingMode.OneWay, FallbackValue = Visibility.Collapsed, Converter = trueToVisible
            });
            _stopButton?.SetBinding(Button.IsEnabledProperty, new Binding {
                Path = "IsStopEnabled", Source = this, Mode = BindingMode.OneWay, FallbackValue = true
            });

            _audioTracksSelectionButton = this.GetTemplateChild(AudioTracksSelectionButtonName) as Button;

            _ccSelectionButton = this.GetTemplateChild(CCSelectionButtonName) as Button;

            _timeElapsedElement = this.GetTemplateChild(TimeElapsedElementName) as TextBlock;

            _timeRemainingElement = this.GetTemplateChild(TimeRemainingElementName) as TextBlock;

            _progressSlider = this.GetTemplateChild(ProgressSliderName) as Slider;
            PropertyChangedCallback callback = OnSliderTemplateChanged;

            _progressSlider?.RegisterDisposablePropertyChangedCallback(Slider.TemplateProperty, callback);

            _bufferingProgressBar = this.GetTemplateChild(BufferingProgressBarName) as ProgressBar;

            _timelineContainer = this.GetTemplateChild(TimelineContainerName) as Border;

            _downloadProgressIndicator = _progressSlider?.GetTemplateChild(DownloadProgressIndicatorName) as ProgressBar;

            _rootGrid = this.GetTemplateChild(RootGridName) as Grid;
            if (_rootGrid != null)
            {
                _rootGrid.Tapped -= OnRootGridTapped;
                _rootGrid.Tapped += OnRootGridTapped;
            }

            if (_mediaPlayer != null)
            {
                BindMediaPlayer();
            }
        }
Пример #4
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);
        }
Пример #5
0
        private void SetSubMenu()
        {
            CircleMenuPanel.Children.Clear();

            foreach (var item in ItemsSource)
            {
                var menuItem = item as CircleMenuItem;
                if (menuItem != null)
                {
                    var btn = new Button();
                    btn.Opacity = 0;
                    var bindTag = new Binding
                    {
                        Path = new PropertyPath("Id"),
                        Source = menuItem,
                        Mode = BindingMode.OneWay
                    };
                    btn.SetBinding(TagProperty, bindTag);//用Tag存储Id

                    var textBlock = new TextBlock();
                    var bindTitle = new Binding
                    {
                        Path = new PropertyPath("Title"),
                        Source = menuItem,
                        Mode = BindingMode.OneWay
                    };
                    textBlock.SetBinding(TextBlock.TextProperty,bindTitle);

                    btn.Content = textBlock;
                    var binding = new Binding()
                    {
                        Path = new PropertyPath("SubMenuStyle"),
                        RelativeSource = new RelativeSource() { Mode = RelativeSourceMode.TemplatedParent },
                        Source = this
                    };
                    btn.SetBinding(StyleProperty, binding);
                    btn.Click += (s, e) =>
                    {
                        VisualStateManager.GoToState(this, VisualStateCollapsed, false);
                        if (SubClickCommand != null)
                        {
                            var sbtn = s as Button;
                            if (sbtn != null)
                                SubClickCommand(Convert.ToInt32(sbtn.Tag));
                        }
                        SetSubMenu();
                        VisualStateManager.GoToState(this, VisualStateExpanded, false);
                    };

                    CircleMenuPanel.Children.Add(btn);
                }
            }
        }
Пример #6
0
        // 依存関係プロパティに値がセットされたときに呼び出されるメソッド
        private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBlock block = new RichTextBlock();
            Tweet tweet = e.NewValue as Tweet;
            Binding detailCommandBinding = new Binding { Path = new PropertyPath("TweetDetailCommand") };

            Binding userDetailCommandBinding = new Binding { Path = new PropertyPath("UserDetailCommand") };

            Binding searchCommandBinding = new Binding() { Path = new PropertyPath("SearchCommand") };

            Binding browseCommandBinding = new Binding() { Path = new PropertyPath("BrowseCommand") };

            Binding previewImageCommandBinding = new Binding() { Path = new PropertyPath("ImagePreviewCommand") };



                SolidColorBrush runForeGround = Application.Current.Resources["ForegroundBrush"] as SolidColorBrush;
                FontFamily tweetFontFamily = Application.Current.Resources["MainFontFamily"] as FontFamily;
                double fontSize = (double)Application.Current.Resources["TimelineFontSize"];
                if (tweet != null)
                {



                    if (tweet.retweeted_status != null)
                    {
                        tweet = tweet.retweeted_status;
                    }

                    
                    Paragraph para = new Paragraph();

                    List<EntitieBase> entities = new List<EntitieBase>();
                    if (tweet.entities != null)
                    {

                        if (tweet.entities.user_mentions != null)
                        {
                            entities.AddRange(tweet.entities.user_mentions);
                        }
                        if (tweet.entities.urls != null)
                        {
                            entities.AddRange(tweet.entities.urls);
                        }
                        if (tweet.entities.hashtags != null)
                        {
                            entities.AddRange(tweet.entities.hashtags);
                        }
                        if (tweet.entities.media != null)
                        {
                            entities.AddRange(tweet.entities.media);
                        }
                    }


                    try
                    {
                        if (tweet.entities != null && entities.Count > 0)
                        {

                            entities.OrderBy(q => q.indices[0]);
                            string back = "";
                            int seek = 0;


                            foreach (EntitieBase entitiy in entities)
                            {

                                int start = entitiy.indices[0];
                                int end = entitiy.indices[1];
                                StringInfo infoText = new StringInfo(tweet.text);
                                back = tweet.text.SubStringByTextElements(end, infoText.LengthInTextElements - end);
                                string front = tweet.text.SubStringByTextElements(seek, start - seek);

                                para.Inlines.Add(new Run { Text = front, Foreground = runForeGround, FontSize = fontSize });
                                var link = new HyperlinkButton();
                                link.Padding = new Thickness(0);
                                // link.Foreground = Application.Current.Resources["AppThemeBrush"] as SolidColorBrush;
                                link.Style = Application.Current.Resources["NeuroniaTimelineHyperlinkButtonStyle"] as Style;
                                link.FontSize = fontSize;

                                var uiContainer = new InlineUIContainer();

                                if (entitiy is UserMention)
                                {
                                    var en = entitiy as UserMention;

                                    link.Content = "@" + en.screen_name;
                                    uiContainer.Child = link;
                                    link.CommandParameter = en.screen_name;
                                    link.SetBinding(HyperlinkButton.CommandProperty, userDetailCommandBinding);
                                }
                                else if (entitiy is TweetUrl)
                                {
                                    var en = entitiy as TweetUrl;
                                    link.Content = en.display_url;
                                    uiContainer.Child = link;
                                    link.CommandParameter = en.url;
                                    link.SetBinding(HyperlinkButton.CommandProperty, browseCommandBinding);

                                }
                                else if (entitiy is HashTag)
                                {
                                    var en = entitiy as HashTag;
                                    link.Content = "#" + en.text;
                                    uiContainer.Child = link;
                                    link.CommandParameter = "#" + en.text;
                                    link.SetBinding(HyperlinkButton.CommandProperty, searchCommandBinding);
                                }
                                else if (entitiy is TweetMedia)
                                {
                                    var en = entitiy as TweetMedia;

                                    Button btn = new Button();
                                    btn.Width = (double)Application.Current.Resources["previewImageWidth"];

                                    //btn.HorizontalAlignment = HorizontalAlignment.Stretch;
                                    btn.Height = (double)Application.Current.Resources["previewImageHeight"];
                                    btn.Style = Application.Current.Resources["NeuroniaTimelineImageButtonStyle"] as Style;
                                    var imageBrush = new ImageBrush() { ImageSource = new BitmapImage(new Uri(en.media_url)), Stretch = Stretch.UniformToFill };
                                    btn.Background = imageBrush;
                                    btn.CommandParameter = en;
                                    btn.SetBinding(Button.CommandProperty, previewImageCommandBinding);
                                    var flyout = Application.Current.Resources["ImagePreviewFlyout"] as Flyout;
                                    flyout.Placement = FlyoutPlacementMode.Top;

                                    var grid = (flyout.Content as Grid);

                                    btn.Flyout = flyout;
                                    uiContainer.Child = btn;

                                    para.Inlines.Add(new LineBreak());
                                }
                                para.Inlines.Add(uiContainer);
                                seek = end;
                            }

                            para.Inlines.Add(new Run { Text = back, Foreground = runForeGround, FontFamily = tweetFontFamily, FontSize = fontSize });


                        }
                        else
                        {
                            para.Inlines.Add(new Run { Text = tweet.text, Foreground = runForeGround, FontFamily = tweetFontFamily, FontSize = fontSize });
                        }

                        block.Blocks.Add(para);
                    }
                    catch (Exception ee)
                    {
                        //Debug.WriteLine(value.ToString());
                    }

                    
                }
            

            (d as ContentControl).Content = block;

            
            
        }