【问题标题】:windows phone 8 button's commandparameter { binding}windows phone 8按钮的命令参数{绑定}
【发布时间】:2013-10-02 11:53:02
【问题描述】:

我对 windows phone 8 有点陌生,迷失在这个 {Binding} 东西中。我想知道这个按钮如何绑定命令参数?这个命令参数绑定到什么?

   <data:MoviesByCategory x:Key="movies"/>
    <data:MoreCommand x:Key="moreCommand" />
 <phone:LongListSelector x:Name="codeMovies" IsGroupingEnabled="true"
                                      ItemsSource="{StaticResource movies}"
                                      ListHeaderTemplate="{StaticResource movieListHeader}"
                                      GroupHeaderTemplate="{StaticResource movieGroupHeader}"
                                      ItemTemplate="{StaticResource movieItemTemplate}"
                                      JumpListStyle="{StaticResource MoviesJumpListStyle}"
                                      toolkit:TiltEffect.IsTiltEnabled="True">

                <!-- The group footer template, for groups in the main list -->
                <phone:LongListSelector.GroupFooterTemplate>
                    <DataTemplate>
                        <Button DataContext="{Binding}" Content="{Binding GetMore}"
                                Command="{StaticResource moreCommand}" CommandParameter="{Binding}"/>
                    </DataTemplate>
                </phone:LongListSelector.GroupFooterTemplate>

【问题讨论】:

    标签: windows-phone-7 windows-phone-8 windows-phone


    【解决方案1】:

    使用{Binding} 将绑定到当前的DataContext,所以设置DataContext="{Binding}" 可以被删除,因为它什么都不做。
    由于CommandParameter="{Binding}" 在 GroupFooterTemplate 中,因此 dataContext 将是您的电影组,因此它将是 CommandParameter 绑定到的内容。

    【讨论】:

    • "可以直接删除,因为它什么都不做。" 除非需要的命令参数是按钮上显示的电影。
    • @Will 不管做什么,设置 DataContext="{Binding}" 没有任何效果,默认情况下 DataContext 会自动从父级继承,因此显式设置它不会有任何效果。重要的绑定是 CommandParameter="{Binding}"。
    • 不,DataContext 流向按钮的 CommandParameter。因此,如果您需要通过 CommandParameter 将 DataContext 的当前内容传递到命令中,您必须使用绑定。说它“完全没有效果”是完全错误的。自己试试吧。
    • @Will 我说 DataContext="{Binding}" 没有效果,不是 CommandParameter="{Binding}"。使用 DataContext="{Binding}" 与执行 this.DataContext=this.DataContext; 完全相同
    • 好了,我现在要去吃虫子了。
    猜你喜欢
    • 1970-01-01
    • 2013-01-03
    • 2014-01-15
    • 2013-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多