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>    
    

      

  • 相关阅读:
    握手挥手状态(转)
    牛客笔记
    Redis常见面试题
    SpringBoot整合Redis及Redis工具类撰写(转)
    Netty中FastThreadLocal源码分析(转)
    计算机网络各层涉及协议(转)
    计算机小网络小笔记
    数据库
    操作系统提供的接口
    可重入锁和不可重入锁
  • 原文地址:https://www.cnblogs.com/CoreXin/p/4428978.html
Copyright © 2011-2022 走看看