如何在TreeView中获取所选的子项

时间:2013-08-19 11:40:33

标签: c# wpf xaml treeview

我有一个TreeView,有两个级别,父母和孩子,我想获得所选孩子的价值。我使用Josh Smith的TreeView with MVVM pattern让我开始并修改了IsSelected方法以获取所选项目,但我总是得到父项。

static object _selectedItem = null;
......
......
public bool IsSelected
    {
        get { return _isSelected; }
        set
        {
            if (value != _isSelected)
            {
                _isSelected = value;
                this.OnPropertyChanged("IsSelected");
                {
                    _selectedItem = this;
                }
            }
        }
    }

我的XAML片段:

Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}"/>
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}"/>
                    <Setter Property="FontWeight" Value="Normal"/>

                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>

0 个答案:

没有答案