WPF DataBinding命令参数不适用于Prism中的树视图

时间:2015-04-13 18:47:40

标签: c# wpf invoke-command prism-5

我正在尝试传递树视图 selectedItem 属性,以便在用户双击树视图项时查看模型。但它始终返回根项已选择项,即使我点击子项目。 以下是供参考的代码。

<i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseDoubleClick">                    
            <prism:InvokeCommandAction Command="{Binding TreeNodeDoubleClickevent}" CommandParameter="{Binding  Path=SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}}">
            </prism:InvokeCommandAction>
        </i:EventTrigger>
        </i:Interaction.Triggers>

下面是完整的xaml代码供参考。

xaml代码:

 <TreeView Name="treeView" Background="Transparent" ItemsSource="{Binding NavigationTreeList,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" TextBlock.MouseRightButtonDown="treeView_MouseRightButtonDown" >        
    <i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseDoubleClick">                    
        <prism:InvokeCommandAction Command="{Binding TreeNodeDoubleClickevent}" CommandParameter="{Binding  Path=SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}}">
        </prism:InvokeCommandAction>
    </i:EventTrigger>
    </i:Interaction.Triggers>
    <TreeView.ItemContainerStyle>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsSelected" Value="{Binding IsSelected,Mode=TwoWay}" />
            <Setter Property="IsExpanded" Value="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type UserControl}},Path=DataContext.IsExpanded, Mode=TwoWay}" />                    
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True">
                    <Setter Property="Background" Value="LightGray"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </TreeView.ItemContainerStyle>
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate  DataType="{x:Type provider:CustomXML}" ItemsSource="{Binding CustomList}">
            <TextBlock  Text="{Binding Name}" Background="{Binding Property.Background}"  Tag="{Binding Parent}" />
        </HierarchicalDataTemplate>               
    </TreeView.ItemTemplate>
</TreeView>

查看型号代码:

public class VM_NavigatorTreeView : IVM_NavigatorTreeView
{
    public DelegateCommand<CustomXML> TreeNodeDoubleClickevent { get; set; } 

    [ImportingConstructor]
    public VM_NavigatorTreeView(IRegionManager regionManager)
        : base(regionManager)
    {
        RegionManager = regionManager; 
        TreeNodeDoubleClickevent = new DelegateCommand<CustomXML>(OnExecute_TreeNodeDouble_click);
    }

    public void OnExecute_TreeNodeDouble_click(CustomXML obj)
    {

    }

}

0 个答案:

没有答案