WPF Treeview自引用子级复选框不会绑定

时间:2018-11-07 09:49:25

标签: c# wpf binding telerik

我正在使用Telerik的WPF RadTreeView。我在每个节点中都有一个复选框和文本块,并且节点具有相同的类型。数据通过ParentId属性进行自我引用。

型号

 public class OloFunctionModel : NotificationBase
{
    public int Id { get; set; }

    public string Name { get; set; }

    public int? ParentId { get; set; }        

    private ObservableCollection<OloFunctionModel> _children;
    public virtual ObservableCollection<OloFunctionModel> Children {
        get
        {
            return this._children;
        }
        set
        {
            this._children = value;
            OnPropertyChanged("Children");
        }
    }

    private OloFunctionModel _parent;
    public OloFunctionModel Parent {
        get
        {
            return this._parent;
        }
        set
        {
            this._parent = value;
            OnPropertyChanged("Parent");
        } 
    }        

    private bool _isChecked = false;
    public bool IsChecked {
        get
        {
            return this._isChecked;
        }
        set
        {
            this._isChecked = value;
            OnPropertyChanged("IsChecked");
        }
    }
}

查看

<telerik:RadTreeView ItemsSource="{Binding TopLevelOloFunctions}" >
<telerik:RadTreeView.ItemTemplate>
    <HierarchicalDataTemplate DataType="{x:Type localModel:OloFunctionModel}" ItemsSource="{Binding Children}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="80" />                    
                <ColumnDefinition Width="100" />
            </Grid.ColumnDefinitions>
            <CheckBox Grid.Column="0" IsChecked="{Binding IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,0,10,0"/>
            <TextBlock Grid.Column="1" Text="{Binding Path=Name}" />                
        </Grid>
    </HierarchicalDataTemplate>
</telerik:RadTreeView.ItemTemplate>

ViewModel

private ObservableCollection<OloFunctionModel> _oloFunctions;
    public ObservableCollection<OloFunctionModel> OloFunctions
    {
        get
        {
            if (_oloFunctions == null)
            {
                _oloFunctions = new ObservableCollection<OloFunctionModel>();
            }
            return this._oloFunctions;
        }
        set
        {
            this._oloFunctions = value;
            OnPropertyChanged("OloFunctions");
        }
    }        

    private ObservableCollection<OloFunctionModel> _topLevelOloFunctions;
    public ObservableCollection<OloFunctionModel> TopLevelOloFunctions
    {
        get
        {
            return new ObservableCollection<OloFunctionModel>(this.OloFunctions.Where(o => o.ParentId == null));
        }
        set
        {
            this._topLevelOloFunctions = value;
            OnPropertyChanged("TopLevelOloFunctions");
        }
    }

节点名称正确显示。我的问题是子节点中的检查框未绑定到模型的IsChecked属性。在父节点中,复选框具有双向绑定功能,可以正常工作。我想念什么吗?

0 个答案:

没有答案
相关问题