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>    
    

      

  • 相关阅读:
    maven项目中各文件都没有报错,但是项目名称有红叉
    executeFind()方法和execute()方法区别
    数据库查询
    getHibernateTemplate出现的所有find方法的总结
    HQL和SQL的区别
    Java创建对象的方式
    xml中的<![CDATA[]]>和转义字符
    DWRUtil.addOptions
    dwr
    response.setHeader("Cache-Control","no-cache");的作用
  • 原文地址:https://www.cnblogs.com/CoreXin/p/4428978.html
Copyright © 2011-2022 走看看