WPF 实现冒泡排序可视化
实现冒泡排序代码就不过多讲解,主要是实现动画效果思路,本demo使用MVVM模式编写,读者可自行参考部分核心代码,即可实现如视频所示效果。
对于新手了解算法相关知识应该有些许帮助,至于其它类型排序,也可按该思路自行修改实现。
直接上代码,页面布局.xaml代码如下:
<UserControl x:Class="Wpf_MetroListBox.Views.Test.CanvasLabelMove"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf_MetroListBox.Views.Test"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="380"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Canvas x:Name="canvas" Grid.Row="0" Background="White">
</Canvas>
<Grid Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Content="创建序列" HorizontalAlignment="Center" Grid.Column="0" Width="70" Height="35" Command="{Binding CommitCommand}" Style="{DynamicResource btn-info-m}"></Button>
<Button Content="执行排序" HorizontalAlignment="Center" Grid.Column="1" Width="70" Height="35" Command