C# TreeView-绑定到IsExpanded属性

C# TreeView-绑定到IsExpanded属性,c#,wpf,treeview,mvvm-light,C#,Wpf,Treeview,Mvvm Light,我有一个树视图声明如下: <TreeView Grid.Column="0" HorizontalAlignment="Stretch" DockPanel.Dock="Left" ItemsSource="{Binding Path=SomeBinding, UpdateSourceTrigger=PropertyChanged}"> <TreeView.ItemContainerStyle> <Style TargetType="{x:T

我有一个树视图声明如下:

<TreeView Grid.Column="0" HorizontalAlignment="Stretch" DockPanel.Dock="Left" ItemsSource="{Binding Path=SomeBinding, UpdateSourceTrigger=PropertyChanged}">
    <TreeView.ItemContainerStyle>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="IsExpanded" Value="{Binding Path=DataContext.DoSmth, UpdateSourceTrigger=PropertyChanged, 
                                                            RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TreeView}}}"/>
        </Style>
    </TreeView.ItemContainerStyle>
    <TreeView.ItemTemplate>
        <HierarchicalDataTemplate ItemsSource="{Binding SomeOtherBinding}">
            <TextBlock Text="{Binding}" />
        </HierarchicalDataTemplate>
    </TreeView.ItemTemplate>
</TreeView>
不幸的是,这个绑定不起作用,并且没有调用DoSmth

编辑

我添加了此代码,但它也不起作用:

<i:Interaction.Triggers>
    <i:EventTrigger EventName="TreeViewItem.Expanded">
        <i:InvokeCommandAction Command="{Binding Path=DataContext.DoSmth}" CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource AncestorType={x:Type TreeView}}}" />
    </i:EventTrigger>
</i:Interaction.Triggers>
编辑


我想绑定到TreeViewItem,我想我在这两个代码段上都这么做了。如果这些项目中的任何一项将被展开,我也希望能够运行DoSmth命令

我不知道您想要实现什么,但iExpanded是bool属性而不是事件或命令那么当TreeItem展开时,运行DoSmth命令的其他方法是什么?您正在查找TreeItem。展开的事件和检查问题请检查请删除我编辑的问题。除非视图模型具有DataContext属性,否则它应该是Command={Binding Path=DoSmth},而不是Command={Binding Path=DataContext.DoSmth}。您的视图模型在这里是上下文。不是TreevieItem