I have 2 problems:
Problem 1:
I need to develop a tree view like structure in my application with MVVM approch.The object(collecion of my class) which I am binding will be of type parent child relationship datawhere parent and child classes are same.(Self refrencing data)
For Ex: Class UserAccess{ public string UserName { get;set; } public bool Read { get;set; } public bool Write { get;set; } public bool Switch { get;set; } List<UserAccess> SubUsersAccess {get; set;} }
Now I have to display the data in hierarchical structure with the checkboxes. The tree view will be a multicolumn treeview.
The WPF code I am using is like this:
<Border BorderThickness="10" BorderBrush="Azure" CornerRadius="10" Width="500"> <TreeView Background="#D6E5F9" ItemsSource="{Binding AggregationUnit, UpdateSourceTrigger=PropertyChanged}"
Width="400" > <TreeView.Resources> <HierarchicalDataTemplate DataType="{x:Type utils:GroupBookEntitlement_AccountTree}"
ItemsSource="{Binding SubAccountTrees, UpdateSourceTrigger=PropertyChanged}"> <StackPanel Orientation="Horizontal" > <Grid > <Grid.ColumnDefinitions> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Text="{Binding NODE}" HorizontalAlignment="Left" /> </Grid> <CheckBox IsChecked="{Binding ReadValue, Mode = TwoWay}" HorizontalAlignment="Center"
Width="100" Margin="10,0,20,0"/> <CheckBox IsChecked="{Binding WriteValue, Mode = TwoWay}" HorizontalAlignment="Center"
Width="100" Margin="0,0,20,0"/> <CheckBox IsChecked="{Binding SwitchValue, Mode = TwoWay}" HorizontalAlignment="Center"
Width="100" Margin="0,0,20,0" />
</StackPanel> </HierarchicalDataTemplate> </TreeView.Resources> </TreeView></Border>
but he problem is allignment of the columns are not matching. Attach snapshot for refrence.
Expected result: All the checkboxes are in sequence and properly alligned.
Problem 2:My second requirement is if I check any parent checkbox, the child checkboxes needs to be automatically chekced and if I uncheck the parent checkbox, child checkboxes are unchecked.
Please let me know how can i achieve this behavior.
Hello Hitesh,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
Thank you for your post. I have been looking into it and I can suggest you use our XamDataTree control instead of MS TreeView, because it has the functionality you need built in. You can see a sample showing it in our samples browser under xamDataTree / Editing and Selection / Using Check Boxes section. If you want to keep using the MS TreeView I can suggest you ask your questions in the MS forums, where you can get an answer from an MS expert.
If you need further assistance on this matter feel free to ask.