当前位置:网站首页 / WPF / 正文

【ay wpf markup】AY XAML应该这样玩-Tower of Hanoi【10/18】

时间:2016年07月22日 | 作者 : aaronyang | 分类 : WPF | 浏览: 1200次 | 评论 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] &lt; 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,”的文章

猜你喜欢

额 本文暂时没人评论 来添加一个吧

发表评论

必填

选填

选填

必填

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

  查看权限

合肥科大智能常年招聘C# .NET CORE,vue前端,JAVA开发,有想换工作的私聊我AY唯一QQ:875556003和AY交流

抖音号:wpfui 工作是wpf,不接活,目前主要折腾maui

AYUI8社区版Github地址:前往获取

杨洋(AaronYang简称AY,安徽六安人)目前是个人,还没公司AY唯一QQ:875556003和AY交流

高中学历,2010年开始web开发,2015年1月17日开始,兴趣学习研究WPF

声明:AYUI7个人与商用免费,源码可购买。部分DEMO不免费.AY主要靠卖技术服务挣钱

不是从我处购买的ayui7源码,我不提供任何技术服务,如果你举报从哪里买的,我可以帮你转正为我的客户,并送demo

查看捐赠

AYUI7.X MVC教程 更新如下:

第一课 第二课 程序加密教程

vs2015 企业版密钥HM6NR-QXX7C-DFW2Y-8B82K-WTYJV

vs2017 企业版密钥NJVYC-BMHX2-G77MM-4XJMR-6Q8QF

标签列表