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.