There is such a DataTemplate

<DataTemplate x:Key="FolderTemplate"> <CheckBox IsChecked="{Binding Path=IsSelected}" Checked="onCheck" Unchecked="OnUnckecked" Tag="{Binding Path=fullName}"> <TextBlock Text="{Binding Path=Name}" /> </CheckBox> </DataTemplate> 

I fill treeview through it:

 TreeViewItem _item = new TreeViewItem(); ////// Folder child = new Folder() { Name = String.Format("{0} ({1}:)", drive.VolumeLabel, drive.Name[0]), IsSelected = false, fullName = drive.Name }; TreeViewItem _node = new TreeViewItem(); _node.Header = child; _node.HeaderTemplate = FindResource("FolderTemplate") as DataTemplate; _node.Tag = drive.Name; _node.Expanded += TreeViewItem_Expanded; _item.Items.Add(_node); FolderTree.Items.Add(_item); 

Events with checkboxes work, but I still need to call OnCheck on the parent node. Tell me how to do it, with xaml, I'm still on "you."

  • one
    I reread it several times and did not understand what you need .. When do you need to call OnCheck on the parent node? Do you really need to call it or is it enough to change the value? Try to describe the problem in more detail .. - Geslot
  • When OnCheck sender is checkbox. I need to get a treeViewItem corresponding to this checkbox. And through him, to mention the parent. - eltarvin
  • Please expand a little listing. It's not entirely clear what happens to _node later. - Geslot
  • Expanded, but there is nothing fundamental happens, just add. - eltarvin
  • If you already build your UI manually, you can manually _node.Checked += DoWhateverYouWant(FolderTree) handler ( _node.Checked += DoWhateverYouWant(FolderTree) ). But you should not want this, in WPF this kind of logic belongs to the view model (and the UI is constructed through xaml). - VladD

0