private static void OnTargetPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DescriptionViewer dv = d as DescriptionViewer;

            if (dv != null)
            {
                bool targetFocused = e.NewValue == FocusManager.GetFocusedElement();
                if (dv.IsFocused != targetFocused)
                {
                    dv.IsFocused = targetFocused;
                }
                dv.LoadMetadata(false);

                FrameworkElement oldElement = e.OldValue as FrameworkElement;
                FrameworkElement newElement = e.NewValue as FrameworkElement;
                EventHandler <ValidationErrorEventArgs> bindingHandler = new EventHandler <ValidationErrorEventArgs>(dv.Target_BindingValidationError);
                RoutedEventHandler gotFocusHandler  = new RoutedEventHandler(dv.Target_GotFocus);
                RoutedEventHandler lostFocusHandler = new RoutedEventHandler(dv.Target_LostFocus);
                if (oldElement != null)
                {
                    oldElement.BindingValidationError -= bindingHandler;
                    oldElement.GotFocus  -= gotFocusHandler;
                    oldElement.LostFocus -= lostFocusHandler;
                }
                if (newElement != null)
                {
                    newElement.BindingValidationError += bindingHandler;
                    newElement.GotFocus  += gotFocusHandler;
                    newElement.LostFocus += lostFocusHandler;
                }
                dv.ParseTargetValidState();
            }
        }
Exemple #2
0
        public GameBananaModDownloadWindow(GBAPIItemDataBasic item, string url)
        {
            InitializeComponent();
            URL  = url;
            Item = item;
            ModTitleLabel.Content    = item.ModName;
            ModSubtitleLabel.Content = item.Subtitle;
            SubmitterLabel.Text      = ProcessCredits(item.Credits);

            // Description
            DescriptionViewer.LoadCompleted += DescriptionViewer_LoadCompleted;
            DescriptionViewer.NavigateToString($"<html><body><style>{Properties.Resources.GBStyleSheet}</style>{item.Body}</body></html>");

            WebClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
            WebClient.DownloadDataCompleted   += WebClient_DownloadDataCompleted;

            // Loads an Image if the submission contains one
            if (item.ScreenshotURL != null)
            {
                var imageSource = new BitmapImage();
                imageSource.BeginInit();
                imageSource.UriSource = new Uri(item.ScreenshotURL);
                imageSource.EndInit();
                SubmissionImage.Source = imageSource;
            }
        }
        public void CreateInstance()
        {
            DescriptionViewer dv = new DescriptionViewer();

            Assert.IsNotNull(dv);
            Assert.IsNull(dv.Description);
            Assert.IsNull(dv.GlyphTemplate);
            Assert.IsNull(dv.ToolTipStyle);
        }
        private static void OnIsValidPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DescriptionViewer dv = d as DescriptionViewer;

            if (dv != null && !dv.AreHandlersSuspended())
            {
                dv.SetValueNoCallback(DescriptionViewer.IsValidProperty, e.OldValue);
                throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, resources.UnderlyingPropertyIsReadOnly, "IsValid"));
            }
        }
        /// <summary>
        /// Handle the Description field property change event.  This will update the the VSM state.
        /// </summary>
        /// <param name="depObj">The DescriptionViewer that changed its Description value.</param>
        /// <param name="e">The DependencyPropertyChangedEventArgs for this event.</param>
        private static void OnDescriptionPropertyChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)
        {
            // Dependency property changed
            DescriptionViewer dv = depObj as DescriptionViewer;

            if (dv != null)
            {
                dv.UpdateDescriptionState();
            }
        }
        /// <summary>
        /// Called by GetName that gets a human readable name that, in addition to AutomationControlType,
        /// differentiates the control represented by this AutomationPeer.
        /// </summary>
        /// <returns>The string that contains the name.</returns>
        protected override string GetNameCore()
        {
            DescriptionViewer dv = Owner as DescriptionViewer;

            if (dv != null)
            {
                return(dv.Description);
            }
            return(base.GetNameCore());
        }
        public void GenerateGui(ITimetable timetable)
        {
            var slots = timetable.ToList();

            ClearGui();
            slots.Sort();
            NoOfSelectedSubjectLabel.Content = GetSubjectCount(slots);
            GenerateTimetableView(slots);
            DescriptionViewer.Update(slots);
        }
        private static void OnPropertyPathPropertyChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs e)
        {
            DescriptionViewer dv = depObj as DescriptionViewer;

            if (dv != null && dv.Initialized)
            {
                dv.LoadMetadata(false);
                // Changing the PropertyPath sometimes requires an update for the validation state, since it might be stale.
                dv.ParseTargetValidState();
            }
        }
        private static void OnDataContextPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DescriptionViewer dv = d as DescriptionViewer;

            if (dv != null)
            {
                if (e.OldValue == null || e.NewValue == null || e.OldValue.GetType() != e.NewValue.GetType())
                {
                    // Refresh the metadata, but only if the DataContext's type has changed (or if either is null)
                    dv.LoadMetadata(false);
                }
            }
        }
        public void DescriptionViewerPosition()
        {
            DataFormApp_FieldsDescriptionViewer dataFormApp = new DataFormApp_FieldsDescriptionViewer();

            this.EnqueueCallback(() =>
            {
                this.DataFormAppBase = dataFormApp;

                dataFormApp.dataForm.CurrentItem = new DataClass();
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                DescriptionViewer des1 = this.DataFormDescriptions[0] as DescriptionViewer;
                Label fieldLabel1      = this.DataFormLabels[0] as Label;
                DatePicker datePicker  = this.DataFormInputControls[0] as DatePicker;

                Assert.IsTrue(this.GetPosition(fieldLabel1).X < this.GetPosition(des1).X);
                Assert.IsTrue(this.GetPosition(fieldLabel1).X < this.GetPosition(datePicker).X);
                Assert.IsTrue(this.GetPosition(datePicker).Y == this.GetPosition(des1).Y);

                DescriptionViewer des2 = this.DataFormDescriptions[1] as DescriptionViewer;
                Label fieldLabel2      = this.DataFormLabels[1] as Label;
                TextBox textBox        = this.DataFormInputControls[1] as TextBox;

                Assert.IsTrue(this.GetPosition(fieldLabel2).X < this.GetPosition(des2).X);
                Assert.IsTrue(this.GetPosition(fieldLabel2).X < this.GetPosition(textBox).X);
                Assert.IsTrue(this.GetPosition(textBox).Y == this.GetPosition(des2).Y);

                DescriptionViewer des3 = this.DataFormDescriptions[2] as DescriptionViewer;
                Label fieldLabel3      = this.DataFormLabels[2] as Label;
                TextBox innerTextBox1  = this.DataFormInputControls[2] as TextBox;

                Assert.IsTrue(this.GetPosition(fieldLabel3).X < this.GetPosition(innerTextBox1).X);
                Assert.IsTrue(this.GetPosition(innerTextBox1).X < this.GetPosition(des3).X);
                Assert.IsTrue(this.GetPosition(innerTextBox1).Y == this.GetPosition(des3).Y);

                DescriptionViewer des4 = this.DataFormDescriptions[3] as DescriptionViewer;
                Label fieldLabel4      = this.DataFormLabels[3] as Label;
                TextBox innerTextBox2  = this.DataFormInputControls[3] as TextBox;

                Assert.IsTrue(this.GetPosition(fieldLabel4).X < this.GetPosition(innerTextBox2).X);
                Assert.IsTrue(this.GetPosition(fieldLabel4).X < this.GetPosition(des4).X);
                Assert.IsTrue(this.GetPosition(des4).X < this.GetPosition(innerTextBox2).X);
                Assert.IsTrue(this.GetPosition(des4).Y == this.GetPosition(fieldLabel4).Y);
            });

            this.EnqueueTestComplete();
        }
        public void CreateInstance_NonXAML()
        {
            DescriptionViewerTestPage page = new DescriptionViewerTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameDescriptionViewer.Initialized); });
            this.EnqueueCallback(() =>
            {
                DescriptionViewer dv = new DescriptionViewer();
                dv.Target            = page.nameTextBox;
            });
            EnqueueTestComplete();
        }
 public void ClearGui()
 {
     NoOfSelectedSubjectLabel.Content = "";
     for (var i = 0; i < _addedElement.Count; i++)
     {
         var ui = _addedElement[i];
         if (Grid.Children.Contains(ui))
         {
             Grid.Children.Remove(ui);
         }
     }
     _addedElement.Clear();
     DescriptionViewer.Clear();
     _occupiedIndex = new Dictionary <int, HashSet <int> >();
 }
        public void ChangeDescriptionViewerPositionOnDataForm()
        {
            DataFormApp_Fields dataFormApp = new DataFormApp_Fields();

            dataFormApp.dataForm.CurrentItem = new DataClass();

            this.EnqueueCallback(() =>
            {
                this.DataFormAppBase = dataFormApp;
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                foreach (DataField field in dataFormApp.dataForm.Fields)
                {
                    DescriptionViewer descriptionViewer = this.DataFormDescriptions[0];
                    Label fieldLabel = this.DataFormLabels[0];
                    FrameworkElement inputControl = this.DataFormInputControls[0];

                    Assert.IsTrue(this.GetPosition(fieldLabel).X < this.GetPosition(inputControl).X);
                    Assert.IsTrue(this.GetPosition(inputControl).X < this.GetPosition(descriptionViewer).X);
                }

                dataFormApp.dataForm.DescriptionViewerPosition = DataFieldDescriptionViewerPosition.BesideLabel;
            });

            // Give the DataFields time to update their UI.
            this.EnqueueDelay(100);

            this.EnqueueCallback(() =>
            {
                foreach (DataField field in dataFormApp.dataForm.Fields)
                {
                    DescriptionViewer descriptionViewer = this.DataFormDescriptions[0];
                    Label fieldLabel = this.DataFormLabels[0];
                    FrameworkElement inputControl = this.DataFormInputControls[0];

                    Assert.IsTrue(this.GetPosition(fieldLabel).X < this.GetPosition(descriptionViewer).X);
                    Assert.IsTrue(this.GetPosition(descriptionViewer).X < this.GetPosition(inputControl).X);
                }
            });

            this.EnqueueTestComplete();
        }
        public void TestMetadataStreaming()
        {
            ValidationSummary validationSummary = null;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                validationSummary = this.GetTemplatePart <ValidationSummary>("ValidationSummary");
                Assert.IsNotNull(validationSummary);
                Assert.IsTrue(validationSummary.DisplayedErrors.Count == 0);
                DescriptionViewer description = this.DataFormDescriptions[0] as DescriptionViewer;
                Assert.IsNotNull(description);
                Assert.AreEqual("Bool Property Description", description.Description);
            });

            this.EnqueueTestComplete();
        }
        public void Target_WhenNotInVisualTree()
        {
            DescriptionViewerTestPage page = new DescriptionViewerTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameDescriptionViewer.Initialized); });
            this.EnqueueCallback(() =>
            {
                TextBox tb = new TextBox();
                Binding b  = new Binding("Email");
                tb.SetBinding(TextBox.TextProperty, b);
                tb.DataContext = page.DataContext;

                DescriptionViewer dv = new DescriptionViewer();
                dv.Target            = tb;
                Assert.AreEqual("Your email address", dv.Description);
            });
            EnqueueTestComplete();
        }
        public void EnsureElementNameBindingWorks()
        {
            DataFormApp_TemplatesWithElementNameBinding dataFormApp = new DataFormApp_TemplatesWithElementNameBinding();

            this.DataFormAppBase             = dataFormApp;
            dataFormApp.dataForm.ItemsSource = DataClassList.GetDataClassList(1, ListOperations.All);
            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                ContentPresenter contentPresenter = this.GetTemplatePart <ContentPresenter>("ContentPresenter");
                StackPanel stackPanel             = contentPresenter.Content as StackPanel;
                Label fieldLabel = stackPanel.Children[0] as Label;
                Assert.AreEqual("String Property", fieldLabel.Content);
                DescriptionViewer descriptionViewer = stackPanel.Children[2] as DescriptionViewer;
                Assert.AreEqual("String Property Description", descriptionViewer.Description);
            });

            this.EnqueueTestComplete();
        }
        public void DescriptionViewerPeer()
        {
            DescriptionViewerTestPage page = new DescriptionViewerTestPage();

            this.TestPanel.Children.Add(page);
            DescriptionViewer dv = page.nameDescriptionViewer;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                DescriptionViewerAutomationPeer peer = new DescriptionViewerAutomationPeer(dv);
                Assert.IsNotNull(peer);
                Assert.AreEqual(AutomationControlType.Text, peer.GetAutomationControlType());
                Assert.AreEqual("DescriptionViewer", peer.GetClassName());
                Assert.AreEqual("This is your first name.", peer.GetName());

                dv.Description = "new description";
                Assert.AreEqual(dv.Description, peer.GetName());
            });
            EnqueueTestComplete();
        }
Exemple #18
0
 private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (sender is TabControl t)
     {
         if (t.SelectedIndex == 1)
         {
             var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
             var result   = Properties.Resources.MarkdownStyleHead + "\n" +
                            Markdown.ToHtml(Description.Text, pipeline) + "\n" +
                            Properties.Resources.MarkdownStyleTail;
             var curDir = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/");
             if (curDir.EndsWith("/"))
             {
                 curDir = curDir.Substring(0, curDir.Length - 1);
             }
             result = result.Replace("${ExtensionsDir}", "file://" + curDir + "/Extensions");
             curDir = Environment.GetEnvironmentVariable("temp");
             if (curDir.EndsWith("\\"))
             {
                 curDir = curDir.Substring(0, curDir.Length - 1);
             }
             if (!string.IsNullOrEmpty(_curAddress))
             {
                 try
                 {
                     File.Delete(_curAddress);
                 }
                 catch
                 {
                     //ignored
                 }
             }
             _curAddress = curDir + "\\" + Guid.NewGuid().ToString() + ".html";
             File.WriteAllText(_curAddress, result, Encoding.Unicode);
             DescriptionViewer.Navigate(new Uri(_curAddress));
         }
     }
 }
Exemple #19
0
 private void CylicIndex_CurrentValueChanged(object sender, EventArgs e)
 {
     DescriptionViewer.Update(_timetableList.ToList()[_cylicIndex.CurrentValue].ToList());
 }
Exemple #20
0
        private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!(ListView.SelectedItem is Problem problem))
            {
                return;
            }
            ProblemName.Text    = problem.ProblemName;
            SpecialJudge.Text   = problem.SpecialJudge;
            ExtraFiles.Text     = StringArrCastToString(problem.ExtraFiles);
            InputFileName.Text  = problem.InputFileName;
            OutputFileName.Text = problem.OutputFileName;
            CompileCommand.Text = problem.CompileCommand;
            AddDate.Content     = problem.AddDate;
            DataSetsNumber.Text = problem.DataSets?.Length.ToString() ?? "0";
            Level.Value         = Convert.ToInt32(problem.Level);
            LevelShow.Content   = Level.Value;
            Public.IsChecked    = (problem.Option & 1) != 0;
            Description.Text    = string.IsNullOrEmpty(problem.Description)
                ? Connection.GetProblemDescription(problem.ProblemId)
                : problem.Description;
            var pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build();
            var result   = Properties.Resources.MarkdownStyleHead + "\n" + Markdown.ToHtml(Description.Text, pipeline) +
                           "\n" + Properties.Resources.MarkdownStyleTail; var curDir = AppDomain.CurrentDomain.BaseDirectory.Replace("\\", "/");

            if (curDir.EndsWith("/"))
            {
                curDir = curDir.Substring(0, curDir.Length - 1);
            }
            result = result.Replace("${ExtensionsDir}", "file://" + curDir + "/Extensions");
            curDir = Environment.GetEnvironmentVariable("temp");
            if (curDir.EndsWith("\\"))
            {
                curDir = curDir.Substring(0, curDir.Length - 1);
            }
            if (!string.IsNullOrEmpty(_curAddress))
            {
                try
                {
                    File.Delete(_curAddress);
                }
                catch
                {
                    //ignored
                }
            }
            _curAddress = curDir + "\\" + Guid.NewGuid().ToString() + ".html";
            File.WriteAllText(_curAddress, result, Encoding.Unicode);
            DescriptionViewer.Navigate(new Uri(_curAddress));
            var a = problem.DataSets?.Length ?? 0;

            DataSetsNumber.Text = a.ToString();
            while (ListBox.Items.Count > a)
            {
                foreach (var t in ListBox.Items)
                {
                    if ((t as Grid)?.Name == $"Data{ListBox.Items.Count}")
                    {
                        (t as Grid).Children.Clear();
                    }
                }
                ListBox.Items.RemoveAt(ListBox.Items.Count - 1);
            }
            while (ListBox.Items.Count < a)
            {
                var strreader =
                    new StringReader(
                        Properties.Resources.DataSetControl.Replace("${index}", (ListBox.Items.Count + 1).ToString()));
                var xmlreader = new XmlTextReader(strreader);
                var obj       = XamlReader.Load(xmlreader);
                ListBox.Items.Add((UIElement)obj);
            }
            for (var i = 0; i < ListBox.Items.Count; i++)
            {
                foreach (var t in ListBox.Items)
                {
                    if ((t as Grid)?.Name != $"Data{i + 1}")
                    {
                        continue;
                    }
                    var b = (t as Grid).FindName($"Input{i + 1}") as TextBox;
                    if (b != null)
                    {
                        b.Text = problem.DataSets?[i]?.InputFile ?? string.Empty;
                    }
                    b = (t as Grid).FindName($"Output{i + 1}") as TextBox;
                    if (b != null)
                    {
                        b.Text = problem.DataSets?[i]?.OutputFile ?? string.Empty;
                    }
                    b = (t as Grid).FindName($"Time{i + 1}") as TextBox;
                    if (b != null)
                    {
                        b.Text = problem.DataSets?[i]?.TimeLimit.ToString() ?? string.Empty;
                    }
                    b = (t as Grid).FindName($"Memory{i + 1}") as TextBox;
                    if (b != null)
                    {
                        b.Text = problem.DataSets?[i]?.MemoryLimit.ToString() ?? string.Empty;
                    }
                    b = (t as Grid).FindName($"Score{i + 1}") as TextBox;
                    if (b != null)
                    {
                        b.Text = problem.DataSets?[i]?.Score.ToString(CultureInfo.CurrentCulture) ?? string.Empty;
                    }
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="DescriptionViewerAutomationPeer" /> class.
 /// </summary>
 /// <param name="owner">
 /// The <see cref="DescriptionViewer" /> that is associated with this <see cref="DescriptionViewerAutomationPeer" />.
 /// </param>
 public DescriptionViewerAutomationPeer(DescriptionViewer owner) : base(owner)
 {
 }
Exemple #22
0
 public DescriptionViewerAutomationPeer(DescriptionViewer owner) : base((FrameworkElement)owner)
 {
 }
Exemple #23
0
        protected override string GetNameCore()
        {
            DescriptionViewer owner = base.Owner as DescriptionViewer;

            return((owner == null) ? base.GetNameCore() : owner.Description);
        }