zoukankan      html  css  js  c++  java
  • TreeView 中 MVVM Command Binding

    <HierarchicalDataTemplate x:Key="TreeNodes" ItemsSource="{Binding Path=Childs,Mode=OneWay}" >                
                    <StackPanel Orientation="Horizontal" Height="24" DataContext="{Binding}">
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontSize="12" >
                            <i:Interaction.Triggers>
    						<i:EventTrigger EventName="MouseLeftButtonUp">
                                <i:InvokeCommandAction Command="{Binding SelectCommand}"
                                                        CommandParameter="{Binding Id}"/>
                            </i:EventTrigger>
    					</i:Interaction.Triggers>
                        </TextBlock>
                    </StackPanel>    
    

      按照button中binding 的方式書寫TreeView中的綁定,实际运行中将会没有想过,原因是TreeView中Command默认绑定的是TreeView的DataContext,实际只需要制定正确的Command的源即可。

    <HierarchicalDataTemplate x:Key="TreeNodes" ItemsSource="{Binding Path=Childs,Mode=OneWay}" >                
                    <StackPanel Orientation="Horizontal" Height="24" DataContext="{Binding}">
                        <TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontSize="12" >
                            <i:Interaction.Triggers>
    						<i:EventTrigger EventName="MouseLeftButtonUp">
                                <i:InvokeCommandAction Command="{Binding Path=DataContext.SelectCommand,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Page}}}"
                                                        CommandParameter="{Binding Id}"/>
                            </i:EventTrigger>
    					</i:Interaction.Triggers>
                        </TextBlock>
                    </StackPanel>    
    

      

  • 相关阅读:
    Robot Framework + Selenium library + IEDriver环境搭建
    【转】大话测试数据(一)
    TEST DESIGN TECHNIQUES: AN OVERVIEW
    24 WHEN CAN WE STOP TESTING?
    MySql Trace
    ORGANISING THE TEST CASES
    angular教程
    vue报错一
    sort()
    时间戳
  • 原文地址:https://www.cnblogs.com/CoreXin/p/4428978.html
Copyright © 2011-2022 走看看