时间:2016年07月22日 | 作者 : aaronyang | 分类 : WPF | 浏览: 1626次 | 评论 0 人
<UserControl x:Class="Markup.Programming.Samples.TowerOfHanoi" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:p="http://www.ayjs.net/markup" Height="300" Width="300"> <UserControl.Resources> <p:ResourceObject x:Key="ViewModel"> <p:Property PropertyName="Posts"> <p:Collection> <p:Iterator> <p:For Var="$i" Value="0" UpperLimit="4" Increment="1"> <p:Yield Path="$i + 1"/> </p:For> </p:Iterator> <p:Collection/> <p:Collection/> </p:Collection> </p:Property> <p:Property PropertyName="HoldingPost"> <p:Collection/> </p:Property> <p:Property PropertyName="SelectedPost"/> <p:Property PropertyName="SelectCommand"> <p:Command> <p:Command.Functions> <!-- CanExecute always says "OK" --> <p:Function Prototype="CanExecute()"> <p:Return Path="true"/> </p:Function> <p:Function Prototype="Execute($parameter)"> <p:Function Prototype="$MoveItem($fromCollection, $toCollection)"> <p:Call Path="$toCollection.Insert(0, $fromCollection[0])"/> <p:Call Path="$fromCollection.RemoveAt(0)"/> </p:Function> <p:Set Path="SelectedPost = $parameter"/> <p:If Path="HoldingPost.Count == 0"> <p:If.Then> <p:When Path="SelectedPost.Count != 0"> <p:Call Path="$MoveItem(SelectedPost, HoldingPost)"/> </p:When> </p:If.Then> <p:If.Else> <p:When> <p:Operator Op="OrOr"> <p:Get Path="SelectedPost.Count == 0"/> <p:Get Path="HoldingPost[0] < SelectedPost[0]"/> </p:Operator> <p:Call Path="$MoveItem(HoldingPost, SelectedPost)"/> </p:When> </p:If.Else> </p:If> </p:Function> </p:Command.Functions> </p:Command> </p:Property> </p:ResourceObject> </UserControl.Resources> <Grid Name="LayoutRoot" DataContext="{Binding Value, Source={StaticResource ViewModel} }"> <StackPanel> <StackPanel.Resources> <DataTemplate x:Key="DiskTemplate"> <Rectangle Margin="1" Height="10" Fill="Red" Stroke="White" HorizontalAlignment="Center"> <Rectangle.Width> <Binding> <Binding.Converter> <p:ResourceConverter ConvertPath="@Value * 20"/> </Binding.Converter> </Binding> </Rectangle.Width> </Rectangle> </DataTemplate> <ItemsPanelTemplate x:Key="PanelTemplate"> <StackPanel/> </ItemsPanelTemplate> </StackPanel.Resources> <Grid Background="PaleTurquoise"> <TextBlock Text="Tower of Hanoi" FontSize="20" TextAlignment="Center"/> </Grid> <Grid Margin="0,3,0,0" Background="PaleGreen" Height="25"> <ItemsControl ItemsSource="{Binding HoldingPost}" ItemsPanel="{StaticResource PanelTemplate}" ItemTemplate="{StaticResource DiskTemplate}" VerticalAlignment="Center"/> </Grid> <ItemsControl ItemsSource="{Binding Posts}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Border Margin="3" BorderThickness="5" BorderBrush="LightGray" Height="100" Width="94"> <Grid Background="Pink"> <p:Attached.Operations> <p:CallHandler Context="{Binding DataContext, ElementName=LayoutRoot}" Path="MouseLeftButtonDown => SelectCommand.Execute" Argument="{Binding}"/> </p:Attached.Operations> <Rectangle Margin="0,5,0,0" Width="10" Fill="Brown" HorizontalAlignment="Center"/> <ItemsControl ItemsSource="{Binding}" ItemsPanel="{StaticResource PanelTemplate}" ItemTemplate="{StaticResource DiskTemplate}" VerticalAlignment="Bottom"/> </Grid> </Border> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </StackPanel> </Grid> </UserControl>
====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======请不要转载谢谢了。=========
推荐您阅读更多有关于“WPF4.5,”的文章
抖音:wpfui 工作wpf,目前主maui
招聘合肥一枚WPF工程师,跟我一个开发组,10-15K,欢迎打扰
目前在合肥市企迈科技就职
AYUI8全源码 Github地址:前往获取
杨洋(AaronYang简称AY,安徽六安人)和AY交流
高中学历,2010年开始web开发,2015年1月17日开始学习WPF
声明:AYUI7个人与商用免费,源码可购买。部分DEMO不免费
不是从我处购买的ayui7源码,我不提供任何技术服务,如果你举报从哪里买的,我可以帮你转正为我的客户,并送demo
查看捐赠AYUI7.X MVC教程 更新如下:
第一课 第二课 程序加密教程
额 本文暂时没人评论 来添加一个吧
发表评论