Skip to content

Commit

Permalink
Stackpanel considered harmful; also update XmlDocument read
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWBrooks committed Aug 26, 2024
1 parent ed41b82 commit 9a74aab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
26 changes: 16 additions & 10 deletions Copyvios/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
<SolidColorBrush x:Key="Mediumlight" Color="#FFD0B0" />
<SolidColorBrush x:Key="GrayText" Color="{DynamicResource {x:Static SystemColors.GrayTextColorKey}}" />
</Window.Resources>
<StackPanel HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" >
<StackPanel.Resources>
<Grid HorizontalAlignment="Left">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.Resources>
<Style TargetType="Label">
<Setter Property="Margin" Value="2"/>
<Setter Property="VerticalAlignment" Value="Center"/>
Expand All @@ -34,7 +38,7 @@
<!-- To allow page and cursor keys to work: -->
<Setter Property="IsReadOnlyCaretVisible" Value="True"/>
</Style>
</StackPanel.Resources>
</Grid.Resources>
<Grid Margin="0,0,0,4">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
Expand All @@ -47,20 +51,22 @@
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Article title:"/>
<TextBox x:Name="articleTitle" HorizontalAlignment="Left" TextWrapping="Wrap" Width="240" Grid.Column="1" TabIndex="1" Margin="4,2"/>
<Button x:Name="CompareButton" Content="Compare" Grid.Column="2" HorizontalAlignment="Center" IsDefault="True" Click="CompareClick" Margin="6,2" />
<TextBox x:Name="articleTitle" HorizontalAlignment="Left" TextWrapping="Wrap" Width="240"
Grid.Column="1" TabIndex="1" Margin="4,2"/>
<Button x:Name="CompareButton" Content="Compare" Grid.Column="2" HorizontalAlignment="Center"
TabIndex="3" IsDefault="True" Click="CompareClick" Margin="6,2" />
<Label x:Name="Progress" Grid.Column="3" />
<Label Content="External URL:" HorizontalAlignment="Left" Grid.Row="1"/>
<TextBox x:Name="URL" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" Grid.ColumnSpan="3" TabIndex="2" Margin="4,2"/>
</Grid>
<Grid Name="ViewGrid">
<Grid Name="ViewGrid" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.Resources>
<Style TargetType="Label">
Expand All @@ -74,20 +80,20 @@
</Grid.Resources>
<Label x:Name="WPHeading" Content="Wikipedia article"/>
<Label Content="External URL" Grid.Column="1"/>
<RichTextBox x:Name="WPViewer" Height="600" Grid.Row="1" IsManipulationEnabled="True">
<RichTextBox x:Name="WPViewer" Grid.Row="1">
<FlowDocument>
<Paragraph x:Name="WPPara">
<Run Text="The WP text will appear here."/>
</Paragraph>
</FlowDocument>
</RichTextBox>
<RichTextBox x:Name="URLViewer" Grid.Column="1" Height="600" Grid.Row="1" IsManipulationEnabled="True">
<RichTextBox x:Name="URLViewer" Grid.Row="1" Grid.Column="1">
<FlowDocument>
<Paragraph x:Name="URLPara">
<Run Text="The external text will appear here."/>
</Paragraph>
</FlowDocument>
</RichTextBox>
</Grid>
</StackPanel>
</Grid>
</Window>
18 changes: 5 additions & 13 deletions Copyvios/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
Expand All @@ -19,7 +20,6 @@ public partial class MainWindow : Window
private readonly Brush graytext;

private readonly string titleBase;
private double StaticHeight;

public MainWindow()
{
Expand Down Expand Up @@ -156,8 +156,10 @@ private void WindowLoaded(object sender, RoutedEventArgs e)

private string StripWP(string wphttp)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(wphttp);
XmlDocument doc = new XmlDocument() { XmlResolver = null } ;
using (XmlReader reader = XmlReader.Create(new StringReader(wphttp))) {
doc.Load(reader);
}
XmlNodeList slotels = doc.GetElementsByTagName("slot");
if (slotels.Count == 0) {
throw new ApplicationException("Wikipedia query didn't return an article");
Expand Down Expand Up @@ -291,18 +293,8 @@ private IEnumerable<Run> SeqToRun(IEnumerable<Sequence> seqs)
}
}

private void Resized(object sender, SizeChangedEventArgs e)
{
double newHeight = this.ActualHeight - StaticHeight;
WPViewer.Height = newHeight;
URLViewer.Height = newHeight;
}

private void Rendered(object sender, EventArgs e)
{
StaticHeight = this.ActualHeight - WPViewer.ActualHeight;
SizeChanged += Resized;

if (BothFieldsPresent()) {
StartComparison();
}
Expand Down

0 comments on commit 9a74aab

Please sign in to comment.