WPF+DiffPlex實(shí)現(xiàn)文本比對(duì)工具
背景
現(xiàn)行的文本編輯器大多都具備文本查詢的能力,但是并不能直觀的告訴用戶兩段文字的細(xì)微差異,所以對(duì)比工具在某種情況下,就起到了很便捷的效率。
關(guān)于 DiffPlex
DiffPlex 是用于生成文本差異的 C# 庫(kù)
準(zhǔn)備
NuGet 包
DiffPlex.Wpf 主要包
MaterialDesignThemes 主題包
代碼實(shí)現(xiàn)
MainWindow.xaml
<Window x:Class="TextComparisonTool.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:diffplex="clr-namespace:DiffPlex.Wpf.Controls;assembly=DiffPlex.Wpf" xmlns:local="clr-namespace:TextComparisonTool" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Title="文本比對(duì)工具" Width="800" Height="450" Icon="DiffPlex.ico" WindowState="Maximized" mc:Ignorable="d"> <Grid Margin="5"> <Grid.RowDefinitions> <RowDefinition Height="40" /> <RowDefinition /> </Grid.RowDefinitions> <WrapPanel> <Button x:Name="BtnInput" Click="BtnInput_Click" Content="輸入文本" Style="{DynamicResource MaterialDesignFlatAccentBgButton}" /> </WrapPanel> <diffplex:DiffViewer x:Name="DiffView" Grid.Row="1" /> </Grid> </Window>
MainWindow.xaml.cs
using System.Windows; namespace TextComparisonTool { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void BtnInput_Click(object sender, RoutedEventArgs e) { InputOldeTextAndNewText input = new(); input.ShowDialog(); if (input.DialogResult is true) { DiffView.OldText = input.txtOldText.Text; DiffView.NewText = input.txtNewText.Text; } } } }
InputOldeTextAndNewText.xaml
<Window x:Class="TextComparisonTool.InputOldeTextAndNewText" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Title="輸入新舊文本" Width="850" Height="500" Icon="DiffPlex.ico" ResizeMode="CanMinimize" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> <Border Margin="5" CornerRadius="11"> <StackPanel> <TextBlock Style="{DynamicResource MaterialDesignBody1TextBlock}" Text="源文本" /> <TextBox x:Name="txtOldText" AcceptsReturn="True" MaxLines="10" MinLines="10" TextWrapping="Wrap" /> <TextBlock VerticalAlignment="Center" Style="{DynamicResource MaterialDesignBody1TextBlock}" Text="新文本" /> <TextBox x:Name="txtNewText" AcceptsReturn="True" MaxLines="10" MinLines="10" TextWrapping="Wrap" /> <Button x:Name="BtnText" Margin="10" Click="BtnText_Click" Content="確認(rèn)" Style="{DynamicResource MaterialDesignFlatButton}" /> </StackPanel> </Border> </Window>
InputOldeTextAndNewText.xaml.cs
using System.Windows; namespace TextComparisonTool { /// <summary> /// InputOldeTextAndNewText.xaml 的交互邏輯 /// </summary> public partial class InputOldeTextAndNewText : Window { public InputOldeTextAndNewText() { InitializeComponent(); } private void BtnText_Click(object sender, RoutedEventArgs e) { DialogResult = true; } } }
效果圖
到此這篇關(guān)于WPF+DiffPlex實(shí)現(xiàn)文本比對(duì)工具的文章就介紹到這了,更多相關(guān)WPF DiffPlex文本比對(duì)工具內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
C#自寫的一個(gè)HTML解析類(類似XElement語(yǔ)法)
這篇文章主要介紹了C#自寫的一個(gè)HTML解析類(類似XElement語(yǔ)法),本文給出了實(shí)現(xiàn)代碼和使用實(shí)例,同時(shí)給出了測(cè)試HTML實(shí)例,需要的朋友可以參考下2015-06-06C# 中使用Stopwatch計(jì)時(shí)器實(shí)現(xiàn)暫停計(jì)時(shí)繼續(xù)計(jì)時(shí)功能
這篇文章主要介紹了C# 中使用Stopwatch計(jì)時(shí)器可暫停計(jì)時(shí)繼續(xù)計(jì)時(shí),主要介紹stopwatch的實(shí)例代碼詳解,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03Unity 使用TexturePacker打包圖集的操作方法
這篇文章主要介紹了Unity 使用TexturePacker打包圖集的操作方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08C#?wpf實(shí)現(xiàn)截屏框熱鍵截屏的示例代碼
這篇文章主要為大家詳細(xì)介紹了C#?wpf實(shí)現(xiàn)截屏框熱鍵截屏的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以學(xué)習(xí)一下2023-09-09WPF實(shí)現(xiàn)繪制扇形統(tǒng)計(jì)圖的示例代碼
這篇文章主要介紹了如何利用WPF繪制扇形統(tǒng)計(jì)圖,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下2022-09-09