Taskbars Selection
You can now allow the end users to select multiple taskbars in FlexyGantt. Below is the code illustration.
This feature is illustrated in the sample that's part of our install: <install path>\Samples\FlexyGantt\DataBinding\FlexyGanttResourceView
Get List of Selected Tasks
You can use SelectedTasks property of MultipleTaskSelector to get a list of underlying model objects corresponding to the selected tasks.
public partial class MainPage : Page { public MainPage() { InitializeComponent(); this.fxgantt.MultipleTaskSelector.Enabled = true; } private void ShowSelectedTaskNames_Click(object sender, RoutedEventArgs e) { String selectedTaskNames = ""; // All selected tasks can be retrived using "fxgantt.MultipleTaskSelector.SelectedTasks" foreach (object task in fxgantt.MultipleTaskSelector.SelectedTasks) { if (task is Task) selectedTaskNames += ((Task)task).TaskName + "\n"; } MessageBox.Show(selectedTaskNames, "Selected Tasks"); } } |
Coloring the selected taskbars
Enable Multiple Task Selector and create a value converter for changing stroke color of taskbar based on selection state.
public class StrokeConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { bool IsSelected = (bool) value; if (IsSelected) return Brushes.Red; else return Brushes.Blue; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } |
In your xaml
Use StrokeConverter to bind the selection state of your task bar. IsSelected property is in TaskItemControl of the taskbar, so we are binding the property using RelativeSource.
<Page ... > <Grid ... > <Grid.Resources> <!-- Stroke converter for taskbar stroke --> <local:StrokeConverter x:Key="strokeConverter"/> </Grid.Resources> <fxgantt:FlexyGantt ... >
<fxgantt:FlexyGantt.TaskItemTemplate> <DataTemplate> <Grid ... > <Rectangle x:Name="taskBar" HorizontalAlignment="Stretch" Fill="{StaticResource TaskItemBarFill}" Stroke="{Binding Path=IsSelected, Converter={StaticResource strokeConverter}, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=fxgantt:TaskItemControl}}" StrokeThickness="1" RadiusX="4" RadiusY="4" /> </Grid> </DataTemplate> </fxgantt:FlexyGantt.TaskItemTemplate> </fxgantt:FlexyGantt> </Grid> </Page> |
Change Selection Key
Default keys for multiple task selection is Control keys (LeftCtrl & RightCtrl). You can use SelectionKeys property of MultipleTaskSelector to change selection keys.
Note: SelectionKeys is a array. So you can set multiple keys as selection keys.
public partial class MainPage : Page { public MainPage() { InitializeComponent(); this.fxgantt.MultipleTaskSelector.Enabled = true; this.fxgantt.MultipleTaskSelector.SelectionKeys = new Key[] { Key.LeftCtrl, Key.RightCtrl, Key.X }; } } |
� RadiantQ 2009 - 2019. All Rights Reserved