WPF TreeView遞迴非同步繫結

2021-06-22 02:16:46 字數 2682 閱讀 2968

using system;   

using system.collections.generic;

using system.linq;

using system.text;

using system.componentmodel;

using system.collections.objectmodel;

namespace departmenttreeview

set

}

private void setcheckstate(bool? value, bool updatechildren, bool updateparent) else if (_ischecked == false)

propertychanged(this, new propertychangedeventargs("ischecked"));

if (updatechildren)

}

if (updateparent && _parent != null)

}

}

private void verifystate() else if (state != currentstate)

}

this.setcheckstate(state, false, true);

}

private bool _i***panded;

public bool i***panded

set

if (!haschildren())

}

}

private object _current;

public object current

set

}

public string displaytext

}

private departmentviewmodel _parent;

public departmentviewmodel parent

set

}

private list_children;

public listchildren

private set

}

#endregion

public static listcreate()

return root.children;

}

private departmentviewmodel(object currentobject)

/// /// 初始化,用於設定父節點

///

private void init()

propertychanged(this, new propertychangedeventargs("children"));

}

/// /// 載入子節點

///

private void loadchildren() ;

if (model.ischecked == true)

children.add(model);

}

init();

}

}

/// /// 判斷是否有子節點(邏輯是:如果只有乙個臨時子節點,說明沒有真正的子節點)

///

///

private bool haschildren()

public observablecollectioncheckeditems

}

public event propertychangedeventhandler propertychanged;

}

}

using system.collections.generic;   

using system.text;

using system.windows;

using system.windows.data;

using system.windows.documents;

using system.componentmodel;

namespace departmenttreeview

private void button_click(object sender, routedeventargs e)

messagebox.show("checked items:/n" + builder.tostring());

}

}

}

當前選中項:

WPF TreeView遞迴遍歷相關方法

1 2 遞迴改變組織樹選中狀態。3 4 5private void recursionorgdatatreestatus orgdata org 614 15 16 1718 獲取選中的組織資料。19 20private void getcheckedorgdata 2129 30 31 32 獲取...

WPF TreeView 支援多選

用過的 wpf 的同學,肯定用過控制項的選擇功能,例如 listbox 或者 datagrid 等。其中有一種控制項 treeview 的多選並沒有我們想象中的那麼開箱即用。之前就遇到乙個需求,treeview 要支援多個選中項,且能從資料端 viewmodel 改變樹節點的選中狀態,然而原生 tr...

wpf treeView新增右擊事件

剛開始接觸wpf,今天學習了下treeview控制項,右擊新增事件。看了很多網上大牛的東西,終究是搞懂了。效果圖如下 xmal部分 treeview name datatreeview margin 1 grid.column 0 grid.row 4 previewmouserightbutton...