Hi,
I am having difficulties in filtering the XamDataTree using triggers and collectionviewsource.
My tree should switch between two Modes based Mode1(Default) and Mode2.
The Object Model looks like below:
Class NodeX
{
....
ObservableCollection<NodeX> Nodes{get; set;}
bool IsSpecialNode {get;set;}
}
public ObservableCOllection<NodeX> NodeXCollection {get; set;} ===> bounds to XamDataTree's ItemSource.
Mode1: should show all the nodes irrespective of the flag (IsSpecialNode )
Mode2: Should show only the nodes whose flag(IsSpecialNode ) is set to true
Option1:
<ig:NodeLayout Key="Nodes" TargetTypeName="NodeBase" DisplayMemberPath="Name" IsDropTarget="{Binding Data.ViewType, ConverterParameter={x:Static data:ViewType.FolderView},Converter={StaticResource ValueEqualsParameterConverter},Source={StaticResource ArticleListBindingProxy}}" > <ig:NodeLayout.NodeStyle> <Style TargetType="{x:Type ig:XamDataTreeNodeControl}"> <Style.Triggers> <MultiDataTrigger> <MultiDataTrigger.Conditions> <Condition Binding="{Binding IsInMode2}" Value="True" /> <Condition Binding="{Binding Path=Data.IsSpecialNode}" Value="False" /> </MultiDataTrigger.Conditions> <MultiDataTrigger.Setters> <Setter Property="Visibility" Value="Collapsed" /> </MultiDataTrigger.Setters> </MultiDataTrigger> </Style.Triggers> </Style> </ig:NodeLayout.NodeStyle>
</ig:NodeLayout>
Option2:
ICollectionView Mode2View;
Mode2View = CollectionViewSource.GetDefaultView(NodeXCollection.Nodes);
Mode2View = CollectionViewSource.GetDefaultView(ProductCollection);if (IsInMode2){ Mode2View.Filter = IsSpecialNode;}else{Mode2View.Filter = null;}
Mode2View.Refresh();
public bool IsSpecialNode(object nodex) { ICollectionView Mode2NodesView = CollectionViewSource.GetDefaultView(((NodeX)nodex).Nodes);Mode2NodesView .Filter = IsSpecialNode;
if (Mode2NodesView .IsEmpty) return ((NodeX)nodex).Items.Any(item=> item.IsSpecial);
return true; }
Both the options doesn't work. Please help me in filtering XamDataTree.
Tree Structure: (There is always one root node and we should display that always)
RootNode
Node1
Node2
Node3
Node4
Thanks,
Sreeni
Hi Sreeni,
The properties used in the trigger do not implement INotifyPropertyChanged. So when clicking to switch modes the property is changing but nothing is notifying the UI that the property has changed. I also want to point out that the SwitchMode method is changing the IsSpecialNode property to true when IsInMode2 is set to true. According to the DataTrigger however, IsInMode2 needs to be "True" and IsSpecialNode needs to be "False" in order for the trigger to pass. Even if you were to implement INotifyPropertyChanged, the trigger conditions will never occur so the nodes won't be hidden.
Hello Rob,
Even after setting the appropriate datacontext, it doesn't seem to be working. I just modifed your sample to reproduce the issue. Please take a look into that. Do we have anyothe rway to filter XamDataTree items?
Where is your IsInMode2 property kept? The binding you are using is looking for that property on the XamDataTreeNode object and that property doesn't exist there. The datacontext for a XamDataTreeNodeControl is a XamDataTreeNode object. You will have to change this binding to point to where your IsInMode2 property is kept. Take a look at my attached sample.