Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can create simple class to hold necessary data. In this class we store lines from each file and <code>Color</code> to indicate equality or not.</p> <pre><code>public class LineComparer { public string Line1 { get; set; } public string Line2 { get; set; } public Brush Color { get; set; } } </code></pre> <p>In the next step you must populate list with data from files:</p> <pre><code>public List&lt;LineComparer&gt; _comparer = new List&lt;LineComparer&gt;(); public void ReadFiles() { TextReader tr1 = new StreamReader("file1.txt"); TextReader tr2 = new StreamReader("file2.txt"); string line1, line2 = null; while ((line1 = tr1.ReadLine()) != null) { _comparer.Add(new LineComparer{ Line1 = line1 }); } int index = 0; while ((line2 = tr2.ReadLine()) != null) { if(index &lt; _comparer.Count) _comparer[index].Line2 = line2; else _comparer.Add(new LineComparer{ Line2 = line2 }); index++; } tr1.Close(); tr2.Close(); _comparer.ForEach(x =&gt; { if(x.Line1 != x.Line2) x.Color = new SolidColorBrush(Colors.Red); else x.Color = new SolidColorBrush(Colors.Green); }); } </code></pre> <p>To present files differences you can use <code>ListBox</code> with <code>ItemTemplate</code>:</p> <pre><code>&lt;ListBox ItemsSource="{Binding}" Grid.IsSharedSizeScope="True" &gt; &lt;ListBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;Grid Background="{Binding Color}"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="*" SharedSizeGroup="A" /&gt; &lt;ColumnDefinition Width="10" /&gt; &lt;ColumnDefinition Width="*" SharedSizeGroup="B" /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock Text="{Binding Line1}" TextWrapping="Wrap" /&gt; &lt;TextBlock Text="{Binding Line2}" TextWrapping="Wrap" Grid.Column="2" /&gt; &lt;/Grid&gt; &lt;/DataTemplate&gt; &lt;/ListBox.ItemTemplate&gt; &lt;/ListBox&gt; </code></pre> <p>Example:</p> <p>"file1.txt":</p> <pre><code>First Second Third Fourth Fifth Sixth Seventh </code></pre> <p>"file2.txt":</p> <pre><code>First second Third Fourth Fifth </code></pre> <p>and the result is:</p> <p><img src="https://i.stack.imgur.com/oKDYu.png" alt="enter image description here"></p> <p><a href="http://sdrv.ms/WQoSGW" rel="nofollow noreferrer">Here</a> is example solution (FileComparer.zip).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload