Unplanned
Last Updated: 16 Feb 2022 10:35 by Martin Ivanov
Martin Ivanov
Created on: 16 Feb 2022 10:35
Category: GanttView
Type: Feature Request
0
GanttView: Provide a better mechanism to data bound properties of SimpleTreeCellContainer to its DataItem
Currently, the SimpleTreeCellContainer has a CLR (non-dependency) property called DataItem, which is of type CellInfo. The CellInfo has its own CLR property named DataItem which points to the corresponding GanttTask object. In some situations the DataItem property is assigned after the XAML evaluation. Because the DataItem properties in the hierarchy are not DependencyProperties and they don't raise the PropertyChanged event, the bindings to the DataItem won't work properly. This is valid in the cases when the DataItem is assigned after the data binding is evaluated, which happens if you have nested items. There is no PropertyChanged, thus the new value won't be accessed.

This was hit when trying to data bind the Background property of SimpleTreeCellContainer to a property of a custom GanttTask.
<Style TargetType="telerik:SimpleTreeCellContainer">
	<Setter Property="Background" Value="{Binding DataItem.DataItem.Background}" /> <!-- where Background is a custom property a custom GanttTask implementation -->
</Style>
Make the DataItem properties (of SimpleTreeCellContainer  and CellInfo) DependencyProperties in order for the data binding to get properly re-evaluated. Or alternatively, provide the GanttTask object as a DataContext of the SimpleTreeCellContainer element. Currently, its DataContext is inherited by the DataContext of RadGanttView.

Currently, one way to set the Background of the SimpleTreeCellContainer is to subscribe to its Loaded event and set the property in code-behind.

<telerik:RadGanttView.Resources>	
	<Style TargetType="telerik:SimpleTreeCellContainer">
		<EventSetter Event="Loaded" Handler="SimpleTreeCellContainer_Loaded" />
	</Style>
</telerik:RadGanttView.Resources>

private void SimpleTreeCellContainer_Loaded(object sender, RoutedEventArgs e)
{
	var container = (SimpleTreeCellContainer)sender;
	var cellInfo = (CellInfo)container.DataItem;
	var task = (CustomTask)cellInfo.DataItem;
	container.Background = task.Background;
}



0 comments