UWP开发:自动生成迷宫&自动寻路算法(1)
2024-08-25 02:48:37
(1)前端篇
首先,我们创建一个新的Universal Windows Platform程序。这些小方块是通过GridView来罗列的,这样可以避免MainPaga.xaml的<Rectangle>元素堆叠太多,并且也好处理数据。
现在我们来看MainPage.xaml到底应该怎么写。
<Grid Background="Black">
<StackPanel Orientation="Vertical">
<GridView Width="1400" Height="730" x:Name="GridView" Margin="0,20,0,0">
<GridView.ItemTemplate>
<DataTemplate>
<Rectangle Width="50" Height="50" Fill="{Binding Color}"/>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
<Button Height="40" Width="200" Content="寻路" Background="CadetBlue" HorizontalAlignment="Center" BorderBrush="CadetBlue" Click="ButtonBase_OnClick"/>
</StackPanel>
</Grid>
<Rectangle Width="50" Height="50" Fill="{Binding Color}"/>
就是地图的地砖啦~
GridView.ItemsSource = Rects;
这里的ItemSource我在C#的后端再进行绑定。
==========================
怎么做到寻路的时候更新地形呢?
首先我考虑到可不可以用ObservableCollection呢?
答案是:不可行!因为ObservableCollection<T>只关注个数的变化,不关注元素的修改。
那怎么做呢?
GridView.ItemsSource = null;
GridView.ItemsSource = Rects;
取消绑定再重新绑定就可以了!
最新文章
- Configure the Windows Firewall to Allow SQL Server Access
- [转]解决a different object with the same identifier value was already associated with the session错误
- ExtJs6.0.0随笔
- 写个PHP框架吧
- ASCII编码表
- Windows 10 Java环境变量配置
- Oracle中synonym和index
- Intellij idea使用postgresql 反向生成实例, &#39;Basic&#39; attribute type should not be &#39;Object&#39;
- HDU 4280 Island Transport(网络流)
- ASP.net button类控件click事件中传递参数
- c++ complie link error 2019/2001
- [转] JavaScript 之 ArrayBuffer
- Mysql for Linux安装配置之—— rpm(bundle)安装
- Event.target和Event.currentTarget的区别
- Ehcache缓存配置和基本使用
- 解决shell命令";** is not in the sudoers file...";错误
- ipmitool命令详解
- python多线程的使用
- 让vs IIS Express支持本地静态Json文件
- Android程序员学WEB前端(2)-HTML(2)-锚点链接列表表单-Sublime
热门文章
- Primer回顾 数组和指针
- 《精通Spring4.X企业应用开发实战》读后感第五章(Bean作用域)
- Sharepoint2013搜索学习笔记之创建搜索服务(二)
- ABP 软删除ISoftDelete
- 2014-9-27 NOIP模拟赛
- LeetCode.8-字符串转整数(String to Integer (atoi))
- linux查看系统版本(适用于centos、ubutun,其他类型没有进行测试)
- CSS3 - CheakBox 开关效果
- JS中比较的数值如何比较大小
- c#基础2-out-ref