Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1770
NodeCheckedChanged executing when unregistered
posted

What I need to happen:

1)I need a datatree whos checkboxes are mutually exclusive. 

2)When I check a checkbox I need to manipulate other UI items based on the selection

3)I need to go back to the view model and update some properties based on the selection

This is what I have:

<ig:XamDataTree x:Name="LogsTree"
ItemsSource="{Binding LogItems}"
NodeCheckedChanged="LogsTree_OnNodeCheckedChanged">
<ig:XamDataTree.CheckBoxSettings>
<ig:CheckBoxSettings CheckBoxVisibility="Visible"/>
</ig:XamDataTree.CheckBoxSettings>
<ig:XamDataTree.SelectionSettings>
<ig:TreeSelectionSettings NodeSelection="Single"/>
</ig:XamDataTree.SelectionSettings>
<ig:XamDataTree.GlobalNodeLayouts>
<ig:NodeLayout Key="Logs" DisplayMemberPath="Text" CheckBoxMemberPath="IsChecked"/>
</ig:XamDataTree.GlobalNodeLayouts>

<i:Interaction.Triggers>

<i:EventTrigger EventName="NodeCheckedChanged" >
<command:EventToCommand Command="{Binding LogSelectionCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>

</ig:XamDataTree>

private void LogsTree_OnNodeCheckedChanged(object sender, NodeEventArgs e)
{
LogsTree.NodeCheckedChanged -= LogsTree_OnNodeCheckedChanged;

var index = e.Node.Index;
foreach (var node in LogsTree.Nodes)
node.IsChecked = false;
LogsTree.Nodes[index].IsChecked = true;

LogsTree.NodeCheckedChanged += LogsTree_OnNodeCheckedChanged;
}

private void LogSelectionChanged(object e)

{

//this is the method that executes in my view model when someone check something the LogTree

}

What happens is that even though I unregistered the NodeCheckedChanged event for LogTree, method LogSelectionChanged command still excutes in my view model because of this code:

foreach (var node in LogsTree.Nodes)
node.IsChecked = false;

I only want it to execute once. Is this possible?

Parents
No Data
Reply
  • 34510
    Verified Answer
    Offline posted

    Hi Kris,

    You can remove the event trigger before the code executes and then re-apply it like you do with the LogsTree_OnNodeCheckedChanged handler.

    var triggers = System.Windows.Interactivity.Interaction.GetTriggers(LogsTree);
    var nodeCheckedTrigger = triggers[0];
    triggers.Remove(nodeCheckedTrigger);

    // do stuff

    triggers.Add(nodeCheckedTrigger);

Children
No Data